多文件上传器Jquery MultiPart解析器不工作JS

时间:2017-04-10 09:31:25

标签: jquery ajax spring jquery-file-upload multifile-uploader

我正在尝试将文件上传到我的前端系统,并作为测试将其本地保存到我的C盘中的文件夹中。我有ajax函数和控制器方法,但似乎无法找出错误消息在spring日志中的含义。

Ajax功能:

    function makeProgress(){                    
      var url = getRelativeURL("web/fileUpload");        
      var formData = new FormData();
      formData.append('file', $('input[type=file]')[0].files[0]);
      console.log("form data " + formData);
      $.ajax({
          url : url,
          data : formData,
          processData : false,
          contentType : "multipart/form-data",
          type : 'POST',
          success : function(data) {
              alert(data);
          },
          error : function(err) {
              alert(err);
          }
     });

        }

服务器端控制器:

private static String UPLOADED_FOLDER = "C://temp//";

@RequestMapping(value = { "/fileUpload" }, method = RequestMethod.POST, consumes ={"multipart/form-data"})
@ResponseBody
public String uploadFile(@RequestParam("file") MultipartFile file, HttpServletRequest req, HttpServletResponse res)
{       
    try {

            byte[] bytes = file.getBytes();
            Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
            Files.write(path, bytes);
            logger.info("You have successfully uploaded '" + file.getOriginalFilename() + "'");
            return("File Uploaded");


    } catch (Exception e) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        logger.error("Failed to upload file '" + file.getOriginalFilename() + "'", e);
        return("File Not Uploaded");
    }
}

错误日志:

2017-04-10 10:30:09.758 DEBUG o.s.web.servlet.DispatcherServlet.976 - Could not complete request 
java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: is a MultipartResolver configured?
    at org.springframework.util.Assert.notNull(Assert.java:112) ~[spring-core-3.2.8.RELEASE.jar:3.2.8.RELEASE]

有人能看到我错过的东西吗?

0 个答案:

没有答案
相关问题