上传图片和音频在android的一个请求上传图片、音频、android

2023-09-11 20:37:21 作者:不忘初心.

如何上传图像和声音一起在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.

我提到这个链接Android:How为.mp3文件上传到http服务器?,这是完全的工作,但我想在这个request.Please添加其他文件,帮我做这件事。 对于什么样的变化,我应该做的Andr​​oid和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.