我们有一个接受图像上传的servlet。有时,当上传源于我们的iPhone客户端(脆弱的连接)时,保存的图像可能会部分或完全变灰。我怀疑这是由于连接过早终止,servlet最终处理的是不完整的图像。
最好的治疗方法是什么?有没有一种方法可以查看整个图像是否在处理前上传?我应该使用HTTP Content-Length头并将上传的内容与这个数字进行比较吗?
谢谢!
一些上下文代码:
@Path("images/")
@POST
@Consumes("image/*")
@Produces({"application/xml", "application/json"})
public AbstractConverter postImage(byte[] imageData) {
BufferedImage bufferedImage = null;
try {
bufferedImage = ImageIO.read(new ByteArrayInputStream(imageData));
} catch (Exception e) {
}
if (bufferedImage == null) {
throw new PlacesException("Image data not provided or could not be parsed", Response.Status.BAD_REQUEST);
}
...
BufferedImage scaledImage = ImageTool.scale(bufferedImage, imageSize);