Uploadify onComplete is not getting called



我正在使用spring-mvc和jquery uploadify上传图像,我的uploadify脚本将图像保存在我的服务器上,我的图像正在保存,但uploadify抛出HTTP错误并且onComplete没有被触发。我确保我的脚本返回了一些东西。这是我的代码。

 $(document).ready(function() {
             $('#upload').click(function() {
                 $('#uploadify').uploadifyUpload();
                    return false;
                 });
                 $('#uploadify').uploadify({
                    'uploader': 'js/uploadify/uploadify.swf',
                    'script': 'uploadcreate.htm;jsessionid=${sessionId}',
                    'multi': false,
                    'auto' : true,
                    'fileDesc': 'JPG Image Files (*.jpg),JPG Image Files (*.JPG),JPG Image Files (*.JPEG)',
                    'fileExt' : '*.jpg;*.jpeg;*.JPEG;',
                    'cancelImg': 'js/uploadify/cancel.png',
                    onComplete: function (event, queueID, fileObj, response, data) {
                        alert("as");
                        //$("#showimage").html('<img src="' + response + '" height="500" width="500" /><br />http://localhost:8080' + fileObj.filePath);
                         }
                 });
         });

我的控制器代码是:

@RequestMapping(value="/uploadcreate.htm", method = RequestMethod.POST)
    public JSONObject uploadcreate(UploadProperties uploadbean, BindingResult result, HttpServletRequest request, Model model) {
        System.out.println("started uploading");
        if (result.hasErrors()) {
            for (ObjectError error : result.getAllErrors()) {
                System.err.println("Error in uploading: " + error.getCode()
                        + " - " + error.getDefaultMessage());
            }
            return null;
        }
        String relativeWebPath = "/WEB-INF/uploads";
        String absoluteFilePath = request.getServletContext().getRealPath(relativeWebPath);
        String username = request.getUserPrincipal().getName();
        JSONObject filepath = uploadFacade.upload(uploadbean, username, absoluteFilePath);
        model.addAttribute("filePath", filepath);
        return filepath;
    }

上述实现的主要问题是 sessionId,我的 spring 安全性以某种方式创建了不同的会话 ID,这就是我的请求没有得到身份验证的原因。我像这样从我的 spring 安全配置文件中删除了安全性

<intercept-url pattern="/uploadcreate.htm" filters="none" />

在那之后,我遇到了其他一些问题,但我通过正确处理会话绕过了这个问题。

最新更新