1 Reply Latest reply on Jul 13, 2012 3:27 PM by ctomc

    Can't upload 4MB jpeg file into database via JBOSS 7.1.1.Final

    samwun9988

      Hi,

       

      Here is my controller code:

       

       

      @RequestMapping(method = RequestMethod.POST)

                public String create(UploadItem uploadItem, BindingResult result,

                                    HttpServletRequest request, HttpServletResponse response,

                                    HttpSession session) {

                          if (result.hasErrors()) {

                                    for (ObjectError error : result.getAllErrors()) {

                                              System.err.println("Error: " + error.getCode() + " - "

                                                                  + error.getDefaultMessage());

                                    }

                                    return "categories/upload-category-image";

                          }

       

       

                          // Some type of file processing...

                          logger.debug("-------------------------------------------");

                          try {

                                    MultipartFile file = uploadItem.getFileData();

                                    String fileName = null;

      //                              InputStream inputStream = null;

                                    OutputStream outputStream = null;

                                    if (file.getSize() > 0) {

       

       

                                              if (file.getSize() > 100000000) {

                                          logger.debug("File Size:::" + file.getSize());

                                          return "categories/upload-category-image";

                                              }

                                              logger.debug("size::" + file.getSize());

                                      logger.debug("Category Id==>" + uploadItem.getId());

       

       

                                      fileName = file.getOriginalFilename();

                                              outputStream = new FileOutputStream(fileName);

                                              logger.debug("fileName:" + file.getOriginalFilename());

                                      outputStream.write(file.getBytes());

       

       

                                      int pos = fileName.lastIndexOf('.');

                                      String ext = fileName.substring(pos+1);

                                      logger.debug("==>Id:"+Integer.parseInt(uploadItem.getId()));

                                      logger.debug("==>ContentType:"+ext);

                                      categoryImageService.create(Integer.parseInt(uploadItem.getId()), fileName, file.getBytes(), ext);

                                              outputStream.close();

       

       

                                    }

       

       

                                    // ..........................................

                                    session.setAttribute("uploadFile", file.getOriginalFilename());

                          } catch (Exception e) {

                                    throw new RuntimeException(e);

                          }

                          return "redirect:/categories/fullList";

                }

       

       

      where if (file.getSize() > 100000000)  means checking if the size > 10MB?

       

      and "categoryImageService.create(Integer.parseInt(uploadItem.getId()), fileName, file.getBytes(), ext);" thrown exception when I tried to upload a 4MB jpeg file. But 9KB is fine.

       

      Any suggestion is very well appreciated.

      Thanks

      Sam