servletsjakarta-eecross-browserjquery-file-uploadajax-upload

Why is my upload error message only received by Edge?


I use MultipartConfig to handle file upload with a Servlet and send an error message if the file is to large:

       private void doUpload(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            response.setContentType("text/plain");
            response.setCharacterEncoding("UTF-8");

            Part filePart;
            try {
                filePart = request.getPart("file");
            } catch (IllegalStateException e) {
                System.out.println("File To Large");
                response.setStatus(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
                PrintWriter writer = response.getWriter();
                writer.println("failure:filetobig");
                writer.flush();
                writer.close();
                return;
            }
         ... (file handling) ...
        }

If I use the Servlet with Jquery-File-Upload (Ajax based) and the file-size exceeds maxFileSize, Edge returns the correct error-message with a status code of 413 and a ready-state of 4. If I do the same with Firefox or Chrome I receive a status-code of 0, a ready-state of 0 and the network-tab in dev-tools shows no answer is received. image

In Firefox the bitrate switches from negative to positive and Chrome return NaN after a while. No matter which browser I use, the System.out.println("File To Large"); is executed. If I execute the Upload-Request with cURL the correct error-message is returned.

My MultipartConfig to test this:

@MultipartConfig(maxFileSize = 1024 * 1024 * 30, // 30 MB
        maxRequestSize = 1024 * 1024 * 1000 // 1000 MB
)

Solution

  • I figured it out: The Server reset the connection because maxSwallowSize is set too low.

    See: https://tomcat.apache.org/tomcat-8.0-doc/config/http.html

    Weirdly enough Edge doesn't care for that and displays the correct message!?