Display image from record of sys_file table

Hi Cuba team,

I’ve successfully uploaded an image and there is a record in sys_file table.
I found a way of using FileDescriptor in the entity class. But since I can’t use the entity mapping, is there any other typical service of Cuba that could help me get the FileDescriptor or image URL from sys_file?

Thanks!

Hi.
Please check our guide Working with Images in CUBA applications.

Regards,
Natalia

1 Like

Hi,

I found a solution. We can just simply put the UUID you got from sys_file to a FileDescriptor.
Check out the code below:

FileDescriptor fileDescriptor = new FileDescriptor();
fileDescriptor.setId((UUID)sysFileUUID);
image.setSource(FileDescriptorResource.class).setFileDescriptor(fileDescriptor);

Or even from a string UUID:

FileDescriptor fileDescriptor = new FileDescriptor();
UUID uuid = UUID.fromString(yourUUID);
fileDescriptor.setId(uuid);
highestSellerAvatar.setSource(FileDescriptorResource.class).setFileDescriptor(fileDescriptor);

In this way, we don’t have to care about entity classes anymore.

1 Like