File Descriptor for Jmix 2.2.0

Hi I am currently using Jmix 2.2.0 and I am slowly importing my cuba project to the latest Jmix manually. I was wondering is there any File Descriptor feature in Jmix which uses the sys_file table in the database or do i need to manually create it?

Hello,

yes, there is. https://docs.jmix.io/jmix/files/file-storage.html
Also https://demo.jmix.io/ui-samples/sample/file-storage-upload-field
You create it manually. I did something like this:
image

While it’s not “ready to use” like in CUBA, this gives more flexibility in having multiple file storage.

Kind regards,
Mladen

Hi, thanks for the answer , I have managed to add it to the database.
image
However, I have few questions on how this file storage works:

  1. The fileRef is pointing to the FileStorage but does the FileStorage stores the actual file into the database or locally?
  2. How does the FileStorage works?
    Sorry for these questions as I am quite blur on how to use this File Ref and File Storage.
  3. If the file is saved locally, how can i save it to the database?
  1. It stores the file, as a file to the location defined by FileStorage. It is a local directory, network shared location, AWS … but it is file as a file, not file as a blob field in a database. Storing files this way is considered best practice in most cases, as you don’t write large binary data into the database and store only details where the file is, name, and other data as needed, such as size, type, comment … you can access the file without reading it from the database. Some use cases, with high security requirements, store files into a database but that is not what most projects need.

  2. You define as many file storages as you need and then use them https://docs.jmix.io/jmix/files/file-storage.html

  3. If you need just few files, this is a good example https://docs.jmix.io/jmix/files/files-in-database.html
    Basically, create an entity to store the file with desired additional data, and then use file upload to pick the file and save it into that JPA entity, which will save it to the database table.
    If you need to transfer more files, then you will need to make a loop to read them all and save.

2 Likes

Okay, thanks for the clarification and i have a better understanding now on how this works. appreciate it for your help !