getStorageDir() hardcoded yyyy/mm/dd storage structure, can it be more customizable?

Hi there,

One app we are working on needs to upload categorized product images for different customers. To make images organized, we designed the storage structure to be something like this:


fileStorageRoot
     |--productImages
                    |--companyA
                    |           |--productCategory1
                    |           |              |-- productImage1.1
                    |           |              |-- productImage1.2
                    |           |              |--  ... ...
                    |           |
                    |           |--productCategory2
                    |                         |-- productImage2.1
                    |                         |-- productImage2.2
                    |                         |--  ... ...
                    | --companyB
                    |            | (similar to companyA structure, so skip here)
                    |

In Product entity, we have a String type attribute “storagePath” which records the folder path where the product image should be stored.

The current implementation in cuba_FileStorage bean hard coded the storage folder structure to be yyyy/mm/dd, which is inflexible.

I noticed this topic that user can override the cuba_FileStorage bean. But it needs to override too many methods:

Could cuba_FileStorage provide a way that user can pass in a customized storagePath String, like “productImages/companyA/productCategory1” when upload a file?

Thanks,
-Mike

1 Like

Sorry the expected storage structure is broken in the previous post. Please see the attached file.

FileUploadExpectedStorageStructure

Hi,

As I see FileStorage.getStorageDir(File rootDir, Date createDate) in default implementation accepts only rootDir and createDate. And at the moment you cannot override this structure in default FileStorage bean, it can be done only if you implement your own FileStorageAPI implementation from scratch.

I think it is the API Usability issue and we should change getStorageDir protected method and introduce there FileDescriptor as a parameter. We have created a YouTrack issue, see the link on the right.

1 Like

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-8576

A post was split to a new topic: Change filestorage folder structure

A post was split to a new topic: Change default filestorage folder structure