上传图片和音频在android的一个请求 [英] upload an image and audio in One request in android

查看:93
本文介绍了上传图片和音频在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添加其他文件,帮我做这件事。 对于什么样的变化,我应该做的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.

这篇关于上传图片和音频在android的一个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆