Package com.vaadin.server.communication
Class FileUploadHandler
- java.lang.Object
-
- com.vaadin.server.communication.FileUploadHandler
-
- All Implemented Interfaces:
RequestHandler
,Serializable
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:
- Serialized Form
-
-
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 ifStreamVariable.isInterrupted()
returnstrue
.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
-
Constructor Summary
Constructors Constructor Description FileUploadHandler()
-
Method Summary
All Methods Instance Methods Concrete 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)
TODO documentprotected boolean
streamToReceiver(VaadinSession session, InputStream in, StreamVariable streamVariable, String filename, String type, long contentLength)
-
-
-
Field Detail
-
DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
public static final int DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
- See Also:
- Constant Field Values
-
-
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 returntrue
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 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 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 content- Throws:
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:
UploadException
-
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
TODO document- Parameters:
request
-response
-- Throws:
IOException
-
-