Java servlet not able to recieve large files

Viewed 166

I built a Java servlet server with Maven and Spring, I am sending large files from an android device to the server. I have successfully sent files of size 6MB to 41MB but when I try send files of size 100MB or more I get the following error on the server:

org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly 

Is this happening because the server is not able to handle request of this size? Is it possible to increase the size of allowed files? How?

Here is my server code:

try {
            List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);//Error happens here
            List<File> files = new ArrayList<File>();//Holds all the files that were received
            HashMap<String, String> map = new HashMap<String, String>();
            for (FileItem item : items) {
                if (item.isFormField()) {
                    // Process regular form field (input type="text|radio|checkbox|etc", select, etc).
                    String fieldName = item.getFieldName();
                    String fieldValue = item.getString();

                map.put(fieldName, fieldValue);
            } else {
                // Process form file field (input type="file").
                String fileName = FilenameUtils.getName(item.getName());//If the name was not specified set default

                String filePath = Constants.ORIGINAL_DIRECTORY_PATH + new SecureRandom().nextInt() + "_" +fileName;
                File storeFile = new File(filePath);
                item.write(storeFile);

                files.add(storeFile);
            }
        }
    } catch (FileUploadException e) {
        throw new ServletException("Cannot parse multipart request.", e);
    }
2 Answers
Related