1

我正在尝试使用 EXIF 数据将图像上传到服务器。这是我的代码:

File file = new File(filePath);

FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];

int bytesRead;
while ((bytesRead = fis.read(b)) != -1) {
    bos.write(b, 0, bytesRead);
}
byte[] bytes = bos.toByteArray();

MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
ByteArrayBody bin = new ByteArrayBody(bytes, "image.jpg");
reqEntity.addPart("file", bin);
postMethod = new HttpPost(url);
postMethod.setEntity(reqEntity);
HttpResponse reply = httpClient.execute(postMethod);

最初,我直接从文件创建了一个 FileBody,但这也没有保留 EXIF 数据。filePath 是我为 Camera 活动提供的路径,用于保存用户拍摄的全尺寸图像。

所以,我的问题是,如何在不丢失 EXIF 信息的情况下上传图片?

4

0 回答 0