Is there some way to limit the parts size sended on a MultipartEntity from the org.apache.http.entity.mime.MultipartEntity ? I need limit this size to 2 MB.
Thanks!
Is there some way to limit the parts size sended on a MultipartEntity from the org.apache.http.entity.mime.MultipartEntity ? I need limit this size to 2 MB.
Thanks!
While sending any file you must have tu reduce size.
Here decodeFile() function will reduce the size of image, when we convert it to bitmap to show selected image. If we send file as it is then large size of image can crash your application. you require 2 MB of size, Yes you can:
public void decodeFile(String filePath) {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 2048;
// Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
bitmap = BitmapFactory.decodeFile(filePath, o2);
imgView.setImageBitmap(bitmap);
Also If you want to upload the full sized image then, just use the filePath.
entity.addPart("uploaded", new FileBody(new File(filepath)));