0

I am getting the following error message after trying to upload an image using a MultipartEntity in android:

Error: Problem with [picture] (File upload error 4)

I am using the following code to upload the image:

String url = "http://www.uploadurl.com/api/files.php";
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);

MultipartEntity multiEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Temp/" +  IMAGE_FILENAME);

ContentBody cBody = new FileBody(file);

StringBody sb1 = new StringBody(getNameFormatted());
StringBody sb2 = new StringBody(getDeviceID());

MultipartEntity multipartContent = new MultipartEntity();
multipartContent.addPart("name", sb1);
multipartContent.addPart("uuid", sb2);
multipartContent.addPart("picture", cBody);

httpPost.setEntity(multipartContent); 

HttpResponse response = httpClient.execute(httpPost, localContext);

I'm not sure what i'm doing wrong, I have uploaded images using code very similar to this in the past only using a JSON array as a part of the entity rather than adding all of them individually. I think it's got something to do with the way the image is set into its ContentBody maybe? I'm really not sure.

halfdan
  • 33,545
  • 8
  • 78
  • 87
SamRowley
  • 3,435
  • 7
  • 48
  • 77

1 Answers1

0

See: Android file uploader with server-side php

Community
  • 1
  • 1
androidworkz
  • 2,902
  • 1
  • 19
  • 19