Android httpPost with parameters and file
You must use a multipart http post, like in HTML forms. This can be done with an extra library. See the post Sending images using Http Post for a complete example.
You have to use MultipartEntity. Find online and download those two libraries: httpmime-4.0.jar and apache-mime4j-0.4.jar and then you can attach as many stuff as desired. Here is example of how to use it:
HttpPost httpost = new HttpPost("URL_WHERE_TO_UPLOAD");
MultipartEntity entity = new MultipartEntity();
entity.addPart("myString", new StringBody("STRING_VALUE"));
entity.addPart("myImageFile", new FileBody(imageFile));
entity.addPart("myAudioFile", new FileBody(audioFile));
httpost.setEntity(entity);
HttpResponse response;
response = httpclient.execute(httpost);
and for server side you can use these entity identifier names myImageFile
, myString
and myAudioFile
.