Let uploaded files keep their filename instead of being renamed to ID

Hey all.

I’m using the upload functionality, and the file’s I upload are renamed to the ID’s they are getting in the database. Is there a setting in which you can adjust this ?

Hi,
are you talking about the upload via REST API? If so, then the filename can be configured in a way described in the swagger documentation. See here: Swagger UI. Take a look at the “name” parameter description.

Hey Max,

Sorry I forgot to mention, but I’m actually talking about the manual upload function in the UI screens.

If you’re talking about how files are saved in the file system, then no, it’s not configurable. File storage is organized this way.

Hey Max,

Okay, that is a huge letdown, since we want to be able to look trough the files on disk manually via the original filename.
And I assume it is not possible to pass trough your own custom id instead of letting the filesystem generate a random id?

Is there any way in Cuba to create a link between an entity, and a file that is stored on the same server, outside the filesystem ?

Thanks!

Just in case, there is a chapter that describes how default file storage implementation works: Standard File Storage Implementation - CUBA Platform. Developer’s Manual
In short, there are FileDescriptor objects in the database and files, stored in the filesystem, have names that are equal to the IDs of corresponding file descriptors.
If you really need specific behavior, you can create your own file storage implementation and store files in a way you want. For example, there is AmazonS3FileStorage implementation in platform. It stores and reads file from Amazon S3.
What do you mean by “create a link between an entity, and a file that is stored on the same server, outside the filesystem”?

What we have is a batch upload of pdf’s to our server, a custom script which checks of there are new pdf’s uploaded, and match them with order entities, and structure them accordingly, to the files are already on our server, which will also run cuba.
My idea was to create a new document entity with the pdf as attachment. What we did next is generate two columns in the orderbrowse screen with linkbuttons, one for viewing the PDF (if it’s linked) in browser, and one for downloading the PDF.

            
Document invoice = new Document();
LinkButton link = componentsFactory.createComponent(LinkButton.class);
FileDescriptor fd = invoice.getAttachment();

link.setAction(new BaseAction("download") {
@Override
public void actionPerform(Component component) {
exportDisplay.show(fd, ExportFormat.OCTET_STREAM);    // for downloading
// exportDisplay.show(fd, ExportFormat.PDF);    for viewing
}
});

Actually this works perfect, with the only downside, since we use a FileDescriptor, that we lose the ability to manually look trough the files on disk, since they are renamed after their UUID. And we would really like to keep that ability.
So I’m looking for a way to save that link between a PDF which we have matched to an order entity. Perhaps saving the path to the file hard coded in the order entity ? I don’t know which workaround there are, as long as we can create those linkbuttons with it.
I hope this clarifies it a bit :slight_smile:

Anyone has a workaround to this yet ?