Class FileUploadHandler

    • Field Detail

      • DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS

        public static final int DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
        See Also:
        Constant Field Values
    • Constructor Detail

      • FileUploadHandler

        public FileUploadHandler()
    • Method Detail

      • handleRequest

        public boolean handleRequest​(VaadinSession session,
                                     VaadinRequest request,
                                     VaadinResponse response)
                              throws IOException
        Description copied from interface: RequestHandler
        Called when a request needs to be handled. If a response is written, this method should return true to indicate that no more request handlers should be invoked for the request.

        Note that request handlers by default do not lock the session. If you are using VaadinSession or anything inside the VaadinSession you must ensure the session is locked. This can be done by extending SynchronizedRequestHandler or by using VaadinSession.accessSynchronously(Runnable) or UI.accessSynchronously(Runnable).

        Specified by:
        handleRequest in interface RequestHandler
        Parameters:
        session - The session for the request
        request - The request to handle
        response - The response object to which a response can be written.
        Returns:
        true if a response has been written and no further request handlers should be called, otherwise false
        Throws:
        IOException - If an IO error occurred
      • doHandleSimpleMultipartFileUpload

        protected void doHandleSimpleMultipartFileUpload​(VaadinSession session,
                                                         VaadinRequest request,
                                                         VaadinResponse response,
                                                         StreamVariable streamVariable,
                                                         String variableName,
                                                         ClientConnector owner,
                                                         String boundary)
                                                  throws IOException
        Method used to stream content from a multipart request (either from servlet or portlet request) to given StreamVariable.

        This method takes care of locking the session as needed and does not assume the caller has locked the session. This allows the session to be locked only when needed and not when handling the upload data.

        Parameters:
        session - The session containing the stream variable
        request - The upload request
        response - The upload response
        streamVariable - The destination stream variable
        variableName - The name of the destination stream variable
        owner - The owner of the stream variable
        boundary - The mime boundary used in the upload request
        Throws:
        IOException - If there is a problem reading the request or writing the response
      • doHandleXhrFilePost

        protected void doHandleXhrFilePost​(VaadinSession session,
                                           VaadinRequest request,
                                           VaadinResponse response,
                                           StreamVariable streamVariable,
                                           String variableName,
                                           ClientConnector owner,
                                           long contentLength)
                                    throws IOException
        Used to stream plain file post (aka XHR2.post(File))

        This method takes care of locking the session as needed and does not assume the caller has locked the session. This allows the session to be locked only when needed and not when handling the upload data.

        Parameters:
        session - The session containing the stream variable
        request - The upload request
        response - The upload response
        streamVariable - The destination stream variable
        variableName - The name of the destination stream variable
        owner - The owner of the stream variable
        contentLength - The length of the request content
        Throws:
        IOException - If there is a problem reading the request or writing the response
      • getProgressEventInterval

        protected int getProgressEventInterval()
        To prevent event storming, streaming progress events are sent in this interval rather than every time the buffer is filled. This fixes #13155. To adjust this value override the method, and register your own handler in VaadinService.createRequestHandlers(). The default is 500ms, and setting it to 0 effectively restores the old behavior.