@Component(value="cuba_FileUploading") public class FileUploading extends java.lang.Object implements FileUploadingAPI, FileUploadingMBean
FileUploadingAPI.FileInfo, FileUploadingAPI.UploadProgressListenerNAME| Constructor and Description |
|---|
FileUploading() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearTempDirectory() |
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.
|
void |
setConfiguration(Configuration configuration) |
java.lang.String |
showTempFiles() |
@Inject public void setConfiguration(Configuration configuration)
public java.util.UUID saveFile(byte[] data)
throws FileStorageException
FileUploadingAPIsaveFile in interface FileUploadingAPIdata - file contentsFileStorageException - in case of IO problemspublic java.util.UUID saveFile(java.io.InputStream stream,
FileUploadingAPI.UploadProgressListener listener)
throws FileStorageException
FileUploadingAPIsaveFile in interface FileUploadingAPIstream - stream which content is to be storedlistener - optional listener to be notified about storing progressFileStorageException - in case of IO problemspublic java.util.UUID createEmptyFile()
throws FileStorageException
FileUploadingAPIcreateEmptyFile in interface FileUploadingAPIFileStorageException - in case of IO problemspublic FileUploadingAPI.FileInfo createFile() throws FileStorageException
FileUploadingAPIcreateFile in interface FileUploadingAPIFileStorageException - in case of IO problemspublic java.util.UUID createNewFileId()
throws FileStorageException
FileUploadingAPIcreateNewFileId in interface FileUploadingAPIFileStorageException - in case of IO problemspublic java.io.File getFile(java.util.UUID fileId)
FileUploadingAPIgetFile in interface FileUploadingAPIfileId - temporary file IDpublic FileDescriptor getFileDescriptor(java.util.UUID fileId, java.lang.String name)
FileUploadingAPIgetFileDescriptor in interface FileUploadingAPIfileId - temporary file IDname - file name to set in the FileDescriptorpublic void deleteFile(java.util.UUID fileId)
throws FileStorageException
FileUploadingAPIdeleteFile in interface FileUploadingAPIfileId - temporary file IDFileStorageException - in case of IO problemspublic void deleteFileLink(java.lang.String fileName)
FileUploadingAPIdeleteFileLink in interface FileUploadingAPIfileName - absolute path to the temporary filepublic void putFileIntoStorage(java.util.UUID fileId,
FileDescriptor fileDescr)
throws FileStorageException
FileUploadingAPIputFileIntoStorage in interface FileUploadingAPIfileId - 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 problemspublic FileDescriptor putFileIntoStorage(TaskLifeCycle<java.lang.Long> taskLifeCycle) throws FileStorageException, java.lang.InterruptedException
FileUploadingAPIBackgroundTask.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);
putFileIntoStorage in interface FileUploadingAPItaskLifeCycle - 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 interruptedpublic void clearTempDirectory()
clearTempDirectory in interface FileUploadingMBeanpublic java.lang.String showTempFiles()
showTempFiles in interface FileUploadingMBean