четверг, 24 декабря 2009 г.

Spring and file uploading

There are many guide how to upload file in spring framework. For example you can use ref .
But when you use it remember:
  • Add multipartResolver bean to spring.xml file!
  • Add fileupload.jar and commons-io.jar from http://commons.apache.org/downloads/download_fileupload.cgi
  • You can use Yahoo uploader or something that. If you do it add parameter name to request.
    For example in yahoo widget use:
    uploader.upload(fileID, url, "post", {}, "file");
  • Remember! SWF can not support cookies. That meens you droped current session. For resolve it simple add ;jsessionid=valuees to upload url.
    Example:
    var url="/reports/uploadFile;jsessionid=F34C5040A029C61658E8CC7A73841CCC"
  • Don't forget return response 200 from controller.
    Example:
    1 @RequestMapping(value = "/reports/uploadFile", method = RequestMethod.POST)
    2 public void uploadFile(@RequestParam("file") MultipartFile file, HttpServletResponse response) throws IOException {
    3
    4 reportStorageService.saveFile(file.getName(), file.getContentType(), file.getSize(), file.getBytes());
    5
    6 response.setStatus(HttpServletResponse.SC_OK);
    7
    8 }

Комментариев нет: