Compress camera image before upload

Take a look over here: ByteArrayOutputStream to a FileBody

Something along these lines should work:

replace

File file = new File(miFoto);
ContentBody foto = new FileBody(file, "image/jpeg");

with

Bitmap bmp = BitmapFactory.decodeFile(miFoto)
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 70, bos);
InputStream in = new ByteArrayInputStream(bos.toByteArray());
ContentBody foto = new InputStreamBody(in, "image/jpeg", "filename");

If file size is still an issue you may want to scale the picture in addition to compressing it.

Leave a Comment