0

I am calling my REST api made using jersey with POST request and I have put my file as a multipart entity

File file=new File(mImageUri.getPath());
MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

multipartEntity.addPart("image", new FileBody(file));

My code is working when the size of image is relatively small (around less than 1 mb) but is getting failed for larger images.

Khwaja Moiz
  • 89
  • 2
  • 10

2 Answers2

0

You have to shrink image to a thumbnail size.

According to android documentation:

For example, it’s not worth loading a 1024x768 pixel image into memory if it will eventually be displayed in a 128x96 pixel thumbnail in an ImageView.

Read this SO post.

Community
  • 1
  • 1
Christian
  • 7,062
  • 9
  • 53
  • 79
  • But I need to upload images in descent qualities. Like users can upload images in OLX – Khwaja Moiz Oct 27 '15 at 13:23
  • 1
    You can downsize image to a large size enough to no use so much memory. All images formats (jpg, png, etc...) are converted to bitmap to order of Android can handle them. But Android just cannot handle large bitmaps (this is hardware limitation). For example, an image with resolution 2048x1536 that is decoded with an inSampleSize of 4 produces a bitmap of approximately 512x384. Loading this into memory uses 0.75MB rather than 12MB for the full image (assuming a bitmap configuration of ARGB_8888) – Christian Oct 27 '15 at 13:27
  • I suggest you to read the docs: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html – Christian Oct 27 '15 at 13:30
  • Okay got it :) but is there any way of uploading larger images without changing their resolution to my database ? – Khwaja Moiz Oct 27 '15 at 13:35
  • Of course! That is nothing about uploading x displaying. I think this is a server limitation! Is your page running over PHP? – Christian Oct 27 '15 at 13:38
  • No I have made a Rest api using jersey(Java) which handles post requests where I simply insert the data into my mysql db. – Khwaja Moiz Oct 27 '15 at 13:40
0

It seems server side issue. Check on serverside if there is any limit set because by default there is limit inside server side for upload image or video like 2mb or 3 mb.

d.k.
  • 415
  • 4
  • 16