我正在创建一个用于拍照和录像的android应用程序。捕获图像后,我想将此图像连同日期和一些文本发送到Web服务器。在服务器端,我正在使用此图片和视频制作应用程序。拍摄的图像将保存在存储卡中。如何使用JSON发送带有文本的图像。我也想将视频发送到Web服务器。
您可以使用Multipart发布请求来执行此操作:(这样,您无需创建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库。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句