byte[] contents = file.getBytes(); Blob blob = new SerialBlob(contents); document.setContent(blob);
byte[] bytes = ...; Blob myBlob = new SerialBlob(bytes);
public static void uploadProfilePicture(File file, String name, String token) { User u = User.find("authToken=?1", token).first(); try { InputStream is = new FileInputStream(file); Blob b = new Blob(); b.set(is, "image/png"); u.profile_picture = b; renderJSON("{\"status\":\"success\"}"); } catch (FileNotFoundException fnf) { Logger.info("File not found when trying to upload profile picture"); renderJSON("{\"status\":\"fail\"}"); } }
ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte b [] = new byte [1024]; int read = 0; while ((read = is.read(b)) != -1) { // add b to baos baos.write(b); } Blob image = new SerialBlob(baos.toByteArray ());
try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; oos = new ObjectOutputStream(bos); // mArrayList is the ArrayList you want to store oos.writeObject(mArrayList); byte[] buff = bos.toByteArray(); // You can store the blob in the database Blob blob = new SerialBlob(buff); } catch (Exception e){ }
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); Blob blob = new Blob(baos.toByteArray());
Blob blob = new Blob(...); AnchorElement a = new AnchorElement(); a.style.display = 'none'; document.body.append(a); String url = Url.createObjectUrlFromBlob(blob); a.href = url; a.download = "file.name"; a.click(); Url.revokeObjectUrl(url);
Blob blobImage = new Blob(); blobImage.set(new FileInputStream(imageFile), MimeTypes.getContentType(imageFile.getName())); MediaItem mediaItem = new Image(blobImage);