在android中的一个请求中上传图像和音频

Vip*_*pin 3 android

如何在Android中一起上传图像和音频?我成功地在一个请求中上传了图像和音频,但是如何添加多个文件.

我推荐这个链接Android:如何将.mp3文件上传到http服务器?它完全正常工作,但我想在此请求中添加另一个文件.请帮我这样做.为此,我应该在android和php方面做什么改变.

use*_*305 14

只需使用httpmime-4.0.jarapache-mime4j-0.4.jar并将实体设置为MultipartEntity.您可以根据需要使用尽可能多的文件.

这是东西,

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);
Run Code Online (Sandbox Code Playgroud)

对于phpside,您可以使用这些实体标识符名称"myImageFile","myAudioFile"并将这些文件移动到适当的文件夹中.