图片上传在 spring 中不起作用

image uploading not working in spring

我有一个spring2.0应用,我们正在使用uploadify jquery插件2.1版本来实现图片上传功能。

问题是: 当我试图在 java 代码中上传任何图像时,它说它的分辨率是 0dpi。但我检查过我是 300dpi。 为什么会这样?我的上传配置是:

$('#imageFile1').uploadify({
'uploader'  : '../uploadify/uploadify.swf',
'script'    : 'images.htm',
'scriptData'    : {'currentFormSpecId' : '${myCommand.formId}'},
'cancelImg' : 'cancel.png',
'auto'      : false,
'multi'     : true,
'wmode'     : 'transparent',
'width'     : 130,
'queueID'   : 'fileQueue',
'queueSizeLimit'    : 15,
'folder'    : '../uploadify',
'fileDesc'  : '*.jpg;*.jpeg;*.tif;*.tiff;*.eps',
'fileExt'   : '*.jpg;*.jpeg;*.tif;*.tiff;*.eps',
'sizeLimit' : 102400000,
'onError': function(event, queueID, fileObj, errorObj) {
// Error display
},
'onComplete': function(event, queueID, fileObj, response, data) {
//success display

});

Java代码

    public ModelAndView uploadImagesToDisk (HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors) throws Exception {
        String currentFormId = request.getParameter("currentFormSpecId");

        DefaultMultipartHttpServletRequest multipartHttpServletRequest = 
                (DefaultMultipartHttpServletRequest) request; 

        MultipartFile multipartFile = multipartHttpServletRequest.getFile("Filedata");

        OutputStream outputStream = null;

        try {
            String imageFileName = multipartFile.getOriginalFilename();
            String imageFileExtension = getFileExtension(multipartFile);
            Image image =  Image.getInstance(multipartFile.getBytes());
        if ((image.getDpiX() < MINIMUM_DPI) || (image.getDpiY() < MINIMUM_DPI)) {
            throw new Exception("ERROR: The image (" + multipartFile.getOriginalFilename() 
                    + ", " + image.getDpiX() + " dpi) " + 
                    " your are attempting to upload does not meet the requirements " +
            "for minimum resolution of 300 dpi. Please upload another image.");
        }

}

在上面的代码中 image.getDpiX() 总是归零。

我注意到一件更奇怪的事情: 当我在我的 window7 机器上检查图像分辨率时,它说它是 300dpi 但是当我在 [=34 中检查相同的图像时=] 服务器机器(使用我正在连接的 citrix,它的屏幕分辨率很低),它显示 96dpi。为什么会这样?

请让我知道你想让我post任何其他事情。

我在这里遇到了两个问题:

  1. 在 java 代码中,它显示图像的 0 DPI 分辨率。所以我 为此找到了两个解决方案
    a) 我发现图片很少 信息丢失,所以我打开那个图像并再次保存 用不同的名字,之后它工作正常。
    b) 我更新 我项目中的 iText.jar 然后它也可以正常工作而无需执行 任何有图像的东西。
  2. 正如@chrylis 在上面的评论中所说,它显示该图像的默认 DPI,因为缺少该信息。