Maybe too late, but it might help someone. I had the same problem. Assuming you have a file object that has the necessary image information
HttpPost post = new HttpPost(YOUR_URL); MultipartEntity entity = new MultipartEntity(); ByteArrayBody body = new ByteArrayBody(file.getData(), file.getName()); String imageTitle = new StringBody(file.getName()); entity.addPart("imageTitle", imageTitle); entity.addPart("image", body); post.setEntity(entity); HttpClient client = new DefaultHttpClient(); HttpResponse response = null; try { response = client.execute(post); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
Please note that MultiPartEntity is part of the HttpMime module. Therefore, you need to put this jar in the lib directory or include the dependency (maven / gradle) in it.
Nikhil
source share