Downloading Files not present in FileStorage

Hi ,
Question 1:-
My application after reading entity table performs a certain logic and write the data into Excel File which i store in Work Directory.
I scanned the documentation and the only way to download is the file to be present in FileStorage.
Is there is a way to access the files directly without Filestorage , if not how to upload the file without UploadField. ?

Question 2:
In the Upload API, is there an option which would replace the older files rather than generating new UUID.

1 Like

Hello,

  1. Yes you can download an arbitrary file located in a directory specified in the cuba.download.directories app property. Use the following code as an example:

public class LogDownloadOptionsWindow extends AbstractWindow {

    private void downloadFile(String filePath) {
        ExportDataProvider dataProvider = new SimpleFileDataProvider(filePath);
        AppConfig.createExportDisplay(this).show(dataProvider, "arbitrary_resource_name.zip");
    }
}

If you decide to use FilStorage, just use methods of FileStorageService from the client side or FileStorageAPI if you create the file on the middleware.

  1. No, FileUploadingAPI allows you only to create new files in FileStorage. But you can use FileStorageService or FileStorageAPI later to remove unneeded files.
1 Like