com.vaadin.server.communication.
Class FileUploadHandler
- java.lang.Object
-
- com.vaadin.server.communication.FileUploadHandler
-
All Implemented Interfaces:
public class FileUploadHandler extends Object implements RequestHandler
Handles a file upload request submitted via an Upload component.
Since:
7.1
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileUploadHandler.SimpleMultiPartInputStream
Stream that extracts content from another stream until the boundary string is encountered.
static class
FileUploadHandler.UploadInterruptedException
An UploadInterruptedException will be thrown by an ongoing upload if
StreamVariable.isInterrupted()
returnstrue
.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
static int
MULTIPART_BOUNDARY_LINE_LIMIT
-
Constructor Summary
Constructors Constructor Description FileUploadHandler()
-
Method Summary
All Methods Modifier and Type Method Description protected void
doHandleSimpleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, String boundary)
Method used to stream content from a multipart request (either from servlet or portlet request) to given StreamVariable.
protected void
doHandleXhrFilePost(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, long contentLength)
Used to stream plain file post (aka XHR2.post(File))
protected int
getProgressEventInterval()
To prevent event storming, streaming progress events are sent in this interval rather than every time the buffer is filled.
boolean
handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
Called when a request needs to be handled.
protected void
sendUploadResponse(VaadinRequest request, VaadinResponse response)
Sends the upload response.
protected boolean
streamToReceiver(VaadinSession session, InputStream in, StreamVariable streamVariable, String filename, String type, long contentLength)
-
-
-
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 usingVaadinSession.accessSynchronously(Runnable)
orUI.accessSynchronously(Runnable)
.Specified by:
handleRequest
in interfaceRequestHandler
Parameters:
session
- The session for the requestrequest
- The request to handleresponse
- 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 variablerequest
- The upload requestresponse
- The upload responsestreamVariable
- The destination stream variablevariableName
- The name of the destination stream variableowner
- The owner of the stream variableboundary
- The mime boundary used in the upload requestThrows:
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 variablerequest
- The upload requestresponse
- The upload responsestreamVariable
- The destination stream variablevariableName
- The name of the destination stream variableowner
- The owner of the stream variablecontentLength
- The length of the request contentThrows:
IOException
- If there is a problem reading the request or writing the response
-
streamToReceiver
protected final boolean streamToReceiver(VaadinSession session, InputStream in, StreamVariable streamVariable, String filename, String type, long contentLength) throws UploadException
Parameters:
in
-streamVariable
-filename
-type
-contentLength
-Returns:
true if the streamvariable has informed that the terminal can forget this variable
Throws:
-
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.
-
sendUploadResponse
protected void sendUploadResponse(VaadinRequest request, VaadinResponse response) throws IOException
Sends the upload response.
Parameters:
request
-response
-Throws:
-
-