图像上传在春天不起作用

时间:2015-04-15 10:08:03

标签: java jquery spring image uploadify

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

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

$('#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但是当我在Windows服务器机器上检查相同的图像时(使用Citrix我是连接,屏幕分辨率低,显示96dpi。为什么会这样?

请让我知道你要我发布任何其他内容。

1 个答案:

答案 0 :(得分:0)

我在这里面临两个问题:

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