Upload
- Usage
- Flow Usage
Defining a Receiver Instance
A Receiver instance should be specified to receive uploaded data.
The receiver provides an OutputStream for the framework, where it writes the content of the received file.
You can implement the interface directly, or use the prebuilt helpers that buffer the file content for later access.
The built-in implementations of Receiver are:
-
FileBuffer -
MemoryBuffer -
MultiFileBuffer -
MultiFileMemoryBuffer.
The last two implement MultiFileReceiver and can be used to upload multiple files at once.
Example: Simple Receiver instance that allows uploading of one file.
Source code
Java
MemoryBuffer memoryBuffer = new MemoryBuffer();
Upload upload = new Upload(memoryBuffer);
upload.addFinishedListener(e -> {
InputStream inputStream = memoryBuffer.getInputStream();
// read the contents of the buffered memory
// from inputStream
});-
The uploaded data is stored in a file on the file system.
-
You can read the data using the
getInputStream()method inMemoryBufferwhen the upload is finished.
You can use a MultiFileReceiver to allow uploading of more than one file.
Example: Using MultiFileMemoryBuffer
Source code
Java
MultiFileMemoryBuffer multiFileMemoryBuffer = new MultiFileMemoryBuffer();
Upload upload = new Upload(multiFileMemoryBuffer);-
The
MultiFileMemoryBufferclass is a ready-made implementation ofMultiFileReceiver. -
The data is stored in files on the file system and you can get the data using a file name and the
getInputStream(String)method.