Using fileUpload as an action in a table

Hello Jmix team,

I’m trying to find a way how to use fileUpload component as an action in a table. Can you help me with a hint?

My idea is to have an action like “Upload new version” in a table with webdav documents without having to go through the manage versions screen.

Thanks!
Konstantin

You can use fileStorageUpload in a buttonsPanel of a table as if it was a regular button, it can look the same:

<fileStorageUpload id="uploadField" 
                   showFileName="false" showClearButton="false"
                   uploadButtonCaption="Upload file" 
                   fileStoragePutMode="MANUAL"/>

The uploaded file can be obtained as follows:

    @Autowired
    private TemporaryStorage temporaryStorage;

    @Autowired
    private FileStorageUploadField uploadField;

    @Subscribe("uploadField")
    public void onUploadFieldFileUploadSucceed(SingleFileUploadField.FileUploadSucceedEvent event) {
        UUID fileId = uploadField.getFileId();
        File file = temporaryStorage.getFile(fileId);
        System.out.println("Uploaded to temporary storage: " + file.getAbsolutePath());
        temporaryStorage.deleteFile(fileId);
    }

Regards,
Konstantin

Yes, this is true. I saw the example in the webdav-documents-browse screen, but this is not the intended behavior.

What I want to achieve is to have the upload action in the actions menu for a table. The approach you suggested seems to be confusing for my client and the need is to be able to upload a new version of a document using the context action menu.

Is it possible to open a file upload dialog through an action and somehow use the FileStorageUploadField functionality for storing the file?

Thanks!
Konstantin

Hi,

Unfortunately, it is impossible to upload a file without FileStorageUploadField because it is a wrapper over <input type="file"/>. As a possible solution, I suggest creating a screen with FileStorageUploadField and show it in a dialog after invoking an action. When screen is closed, obtain information about a file (see doc).

Regards,
Gleb

1 Like