使用spring的放大请求上传多部分文件

时间:2013-12-24 17:58:47

标签: spring jquery spring-mvc file-upload amplifyjs

我正在尝试通过放大请求上传文件和一些数据提交。我正在利用弹簧框架工作。我想上传文件以及一些json数据。我的代码示例如下所示。我收到请求param文件不能作为例外。

amplify.request.define( "UpdateCompanyProfile", 
            "ajax", 
            { 
                url: "updatecomanyprofile.htm", 
                dataType: "json",
                type: "POST"

            }
    );          

    amplify.request({
        resourceId: "UpdateCompanyProfile",
        success: function(data, status) {               
        },
        error: function(data, status) {             
        }
    });
           bus.data.publish({
            topic: "UpdateCompanyProfile.fetch",
            resourceId: "UpdateCompanyProfile",
            successReplyTo: "UpdateCompanyProfile.fetched",
            data: $('#companyProfileForm').serialize() + '&' + $.param(JSON.stringify(companyProfileObj)) 
        });

bus.data.subscribe( "UpdateCompanyProfile.fetched", function(data){
            // my stuff;
        });

和我的控制器

 @RequestMapping(value = UrlPrefix.employer+"/updatecomanyprofile.htm", method = RequestMethod.POST)
public void updateCpmpanyProfile(@ModelAttribute OrganizationDetail organizationDetail, BindingResult bind, ModelMap model, SessionStatus status,@RequestParam("file")MultipartFile f,HttpServletRequest request,HttpServletResponse response) {
    UserBasicInfo user = (UserBasicInfo) request.getSession(false).getAttribute("user");
    ObjectMapper mapper  = null;
    MainJson mainJson = new MainJson();
     mapper = new ObjectMapper();
     try {
         BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
            String json = "";
            if(br != null){
                json = br.readLine();
                mapper = new ObjectMapper();
               logger.logDebug(" Update JSON :"+json);
               organizationDetail = mapper.readValue(json, OrganizationDetail.class);
            }
    } catch (Exception e) {
        e.printStackTrace();
        mainJson.setData(null);
        mainJson.setStatus("error");
    }

}

有人请帮助我。提前谢谢。

0 个答案:

没有答案