Reputation: 505
How to upload an image and audio together in android? I was successful in uploading an image and audio in one request but how to add multiple files.
I referred this link Android:How to upload .mp3 file to http server? and it's perfectly working, but I want to add another file in this request.Please help me to do this. For that what change should I do in the android and php side.
Upvotes: 3
Views: 4314
Reputation: 109237
Just use the httpmime-4.0.jar and apache-mime4j-0.4.jar and set the entity as MultipartEntity
.
you can use as many file as you want.
Here is the stuff,
HttpPost httpost = new HttpPost("url for upload file");
MultipartEntity entity = new MultipartEntity();
entity.addPart("myIdentifier", new StringBody("somevalue"));
entity.addPart("myImageFile", new FileBody(imageFile));
entity.addPart("myAudioFile", new FileBody(audioFile));
httpost.setEntity(entity);
HttpResponse response;
response = httpclient.execute(httpost);
and for php
side you can use these entity identifier names "myImageFile"
and "myAudioFile"
and move these files in appropriate folder.
Upvotes: 14