I am trying to send an image using MultiPartEntity and HttpClient in Android, but keep getting the exception: java.lang.UnsupportedOperationException: Multipart form entity does not implement #getContent()
Here is my code:
public boolean enrollImage(String id, byte[] image) { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("https://example.com/"+id+"/images/"); httpPost.addHeader("Authorization", "Basic " + Base64.encodeToString(("user"+":"+"password").getBytes(),Base64.NO_WRAP)); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("image", new ByteArrayBody(image, "image/jpg", "image.jpg")); httpPost.setEntity(entity); HttpResponse response; try { response = httpClient.execute(httpPost); HttpEntity responseEntity = response.getEntity(); String responseString = EntityUtils.toString(entity); JSONObject json = new JSONObject(responseString); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; } I've added the newer Apache libraries httpmime-4.2.5.jar, httpclient-4.2.5.jar, httpcore-4.2.4.jar, and apache-mime4j-core-0.7.2.jar to my project.
How can I get this this running so that I can POST