我正在创建一个用于拍摄照片和视频的 android 应用程序。捕获图像后,我想将此图像与日期和一些文本发送到 Web 服务器。在服务器端,我正在使用这些图片和视频制作应用程序。拍摄的图像将保存在存储卡中。如何使用 JSON 发送带有文本的图像。我还想将视频发送到网络服务器。
问问题
3592 次
3 回答
1
试试这个在异步任务中将文本、图像上传到服务器
FileBody filebodyVideo = new FileBody(new File(
"Sd Card VideoPath"));
FileBody filebodyVideo1 = new FileBody(new File("Video Upload url"));
StringBody Title= new StringBody("Put Title Here");
StringBody description= new StringBody("Put Desc Here");
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("image", filebodyVideo);
multipartContent.addPart("Title", Title);
multipartContent.addPart("Description", description);
httppost.setEntity(multipartContent);
于 2014-08-08T08:46:51.733 回答
1
您可以使用 Multipart post 请求来执行此操作:(这样,您不需要创建 json)
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(serverURL);
MultipartEntity postEntity = new MultipartEntity();
File file = new File("Your File path on SD card");
postEntity.addPart("fileupload", new FileBody(file, "image/jpeg"));
postEntity.addPart("loginKey", new StringBody(""+loginKey));
postEntity.addPart("message", new StringBody(message));
postEntity.addPart("token", new StringBody(token));
post.setEntity(postEntity);
response = client.execute(post);
您必须添加这个mime4j库。
于 2013-10-10T09:12:27.303 回答
0
You can use this code in your asynctask:
File file = new File("Your File path on SD card");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("YourUrl");
MultipartEntity entity = new MultipartEntity();
entity.addPart("YourKey",new StringBody("Your Text"));
entity.addPart("File", new FileBody(file));
httpost.setEntity(entity);
HttpResponse response = httpclient.execute(httpost);
于 2013-10-10T09:13:56.007 回答