开发者

upload an image and audio in One request in android

开发者 https://www.devze.com 2023-03-27 20:42 出处:网络
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.

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 开发者_JS百科me to do this. For that what change should I do in the android and php side.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号