我正在创建一个用于拍摄照片和视频的 Android 应用程序。捕获图像后,我想将带有日期和一些文本的图像发送到网络服务器。在服务器端,我正在使用这些图片和视频制作一个应用程序。拍摄的图像将保存在存储卡中。如何使用 JSON 发送带有文本的图像。我还想将视频发送到网络服务器。
您可以使用 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 http://sourceforge.net/projects/mime4j/?source=dlp图书馆。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)