public interface FileUploadingAPI
| Modifier and Type | Interface and Description |
|---|---|
static class |
FileUploadingAPI.FileInfo |
static interface |
FileUploadingAPI.UploadProgressListener
Listener to be notified about the progress of uploading file into the temporary storage.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
NAME |
| Modifier and Type | Method and Description |
|---|---|
java.util.UUID |
createEmptyFile()
Create a new empty temporary file and cache its ID for subsequent operations.
|
FileUploadingAPI.FileInfo |
createFile()
Create a new empty temporary file and cache its ID for subsequent operations.
|
java.util.UUID |
createNewFileId()
Create and cache a new temporary file ID.
|
void |
deleteFile(java.util.UUID fileId)
Remove a file from the temporary storage.
|
void |
deleteFileLink(java.lang.String fileName)
Remove an entry from the list of currently cached temporary file IDs, if such exists.
|
java.io.File |
getFile(java.util.UUID fileId)
Return a previously registered temporary file by its ID.
|
FileDescriptor |
getFileDescriptor(java.util.UUID fileId,
java.lang.String name)
Construct a new FileDescriptor for a temporary file to store it in the middleware FileStorage.
|
FileDescriptor |
putFileIntoStorage(TaskLifeCycle<java.lang.Long> taskLifeCycle)
Upload a file from the client's temporary storage into the middleware FileStorage.
|
void |
putFileIntoStorage(java.util.UUID fileId,
FileDescriptor fileDescr)
Upload a file from the client's temporary storage to the middleware FileStorage.
|
java.util.UUID |
saveFile(byte[] data)
Store the byte array in a new temporary file.
|
java.util.UUID |
saveFile(java.io.InputStream stream,
FileUploadingAPI.UploadProgressListener listener)
Store the content of stream in a new temporary file.
|
static final java.lang.String NAME
java.util.UUID saveFile(byte[] data)
throws FileStorageException
data - file contentsFileStorageException - in case of IO problemsjava.util.UUID saveFile(java.io.InputStream stream,
@Nullable
FileUploadingAPI.UploadProgressListener listener)
throws FileStorageException
stream - stream which content is to be storedlistener - optional listener to be notified about storing progressFileStorageException - in case of IO problemsjava.util.UUID createEmptyFile()
throws FileStorageException
FileStorageException - in case of IO problemsFileUploadingAPI.FileInfo createFile() throws FileStorageException
FileStorageException - in case of IO problemsjava.util.UUID createNewFileId()
throws FileStorageException
FileStorageException - in case of IO problems@Nullable java.io.File getFile(java.util.UUID fileId)
fileId - temporary file ID@Nullable FileDescriptor getFileDescriptor(java.util.UUID fileId, java.lang.String name)
fileId - temporary file IDname - file name to set in the FileDescriptorvoid deleteFile(java.util.UUID fileId)
throws FileStorageException
fileId - temporary file IDFileStorageException - in case of IO problemsvoid deleteFileLink(java.lang.String fileName)
fileName - absolute path to the temporary filevoid putFileIntoStorage(java.util.UUID fileId,
FileDescriptor fileDescr)
throws FileStorageException
fileId - file ID in the temporary storagefileDescr - corresponding file descriptor entity. Attention: the FileDescriptor instance must be
stored in the database separately.FileStorageException - in case of IO problemsFileDescriptor putFileIntoStorage(TaskLifeCycle<java.lang.Long> taskLifeCycle) throws FileStorageException, java.lang.InterruptedException
BackgroundTask.run(com.haulmont.cuba.gui.executors.TaskLifeCycle)
TaskLifeCycle.getParams() map must contain the following entries with
String keys:
fileId - file ID in the temporary storagefileName - file name to set in the returned FileDescriptorUsage:
BackgroundTask<Long, FileDescriptor> uploadProgress = new BackgroundTask<Long, FileDescriptor>(2400, ownerWindow) {
@Override
public Map<String, Object> getParams() {
// file parameters
Map<String, Object> params = new HashMap<>();
params.put("fileId", fileUpload.getFileId());
params.put("fileName", fileUpload.getFileName());
return params;
}
@Override
public FileDescriptor run(final TaskLifeCycle<Long> taskLifeCycle) throws Exception {
// upload file to middleware and return FileDescriptor
return fileUploading.putFileIntoStorage(taskLifeCycle);
}
@Override
public void done(FileDescriptor result) {
// commit FileDescriptor to DB
dataService.commit(new CommitContext(result));
}
};
And then we can show upload progress window:
long fileSize = fileUploading.getFile(fileUpload.getFileId()).length();
BackgroundWorkProgressWindow.show(uploadProgress, getMessage("uploadingFile"), null, fileSize, true, true);
taskLifeCycle - task life cycle with specified params: fileId and fileNameFileDescriptor instance must be
stored in the database separately.FileStorageException - in case of IO problemsjava.lang.InterruptedException - in case of uploading thread interrupted