Good day fellow developers.
I\'m busy for android to upload images from a app.
I also got it working (code will follow below).
But when i send large images (
When using ByteArrayOutputStream
and then calling #toByteArray()
you've effectively doubled the amount of memory the JPEG is using. ByteArrayOutputStream
keeps an internal array with the encoded JPEG and when you call #toByteArray()
it allocates a new array & copies the data from the internal buffer.
Consider encoding large bitmaps to a temporary file & using FileOutputStream
and FileInputStream
to encode and send the image.
Without "uploading" - your app survives "nicely" with the just the huge bitmap in memory I assume?
Edit: FileBody
File img = new File(this is where you put the path of your image)
ContentBody cb = new FileBody(img, "File" + pad(random.nextInt(9999) + 1) + ".jpg", "image/jpg", null);
MultipartEntity reqEntity = new multipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("Filedata", cb);
reqEntity.addPart("dropboxId", new StringBody(URLEncoder.encode(uid)));