上传图片和音频在android的一个请求 [英] upload an image and audio in One request in android
问题描述
如何上传图像和声音一起在Android的? 我成功地上传图片和音频于一体的请求,但如何添加多个文件。
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.
我提到这个链接<一个href="http://stackoverflow.com/questions/4966910/androidhow-to-upload-mp3-file-to-http-server">Android:How为.mp3文件上传到http服务器?,这是完全的工作,但我想在这个request.Please添加其他文件,帮我做这件事。 对于什么样的变化,我应该做的Android和PHP端。
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.
推荐答案
只需使用 httpmime-4.0.jar 和 Apache的mime4j-0.4.jar 并设置实体 MultipartEntity
。
只要你想,你可以使用尽可能多的文件。
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.
下面是东西,
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);
和 PHP
端,你可以使用这些实体标识符名称myImageFile
和 myAudioFile
并在相应的文件夹移动这些文件。
and for php
side you can use these entity identifier names "myImageFile"
and "myAudioFile"
and move these files in appropriate folder.
这篇关于上传图片和音频在android的一个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!