File upload in separate folder based on entity

I have two entities where uploading of file is available. Files uploaded for one entity will be deleted regularly whereas for other entity they will remain forever.

How can I save files uploaded from each entity to separate folder. This will make easier for deletion of files (I will just delete folder content on server). If there is any other ways to fulfill this requirement.

Please advise.


You could override FileStorageAPI bean in your project and implement your own logic there:

However interface of FileStorageAPI doesn’t know anything about entity owning the FileDescriptor. So you would need to invent some hacks to distinguish owning entities.

I think it will be easier for you to find required files for cleaning by making SQL request and joining owning entity with file descriptors:

select f.* from sys_file f join my_entity e where e.file_id =

Thanks, I have implemented solution as suggested by you and it is working.