public class FileUploadHandler extends Object implements RequestHandler
Modifier and Type | Class and 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() returns true . |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS |
static int |
MULTIPART_BOUNDARY_LINE_LIMIT |
Constructor and Description |
---|
FileUploadHandler() |
Modifier and Type | Method and 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) |
public static final int MULTIPART_BOUNDARY_LINE_LIMIT
public static final int DEFAULT_STREAMING_PROGRESS_EVENT_INTERVAL_MS
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException
RequestHandler
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)
.
handleRequest
in interface RequestHandler
session
- The session for the requestrequest
- The request to handleresponse
- The response object to which a response can be written.IOException
- If an IO error occurredprotected void doHandleSimpleMultipartFileUpload(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, String boundary) throws IOException
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.
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 requestIOException
- If there is a problem reading the request or writing the
responseprotected void doHandleXhrFilePost(VaadinSession session, VaadinRequest request, VaadinResponse response, StreamVariable streamVariable, String variableName, ClientConnector owner, long contentLength) throws IOException
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.
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 contentIOException
- If there is a problem reading the request or writing the
responseprotected final boolean streamToReceiver(VaadinSession session, InputStream in, StreamVariable streamVariable, String filename, String type, long contentLength) throws UploadException
in
- streamVariable
- filename
- type
- contentLength
- UploadException
protected int getProgressEventInterval()
protected void sendUploadResponse(VaadinRequest request, VaadinResponse response) throws IOException
request
- response
- IOException
Copyright © 2018 Vaadin Ltd. All rights reserved.