Best practice using resources (static files)

Hi,
I have to use some files in my application. for example, I need to use several PDF files and send them as attachment. I also need to access them in tests.

Where is the location to place static resources files in CUBA project and how to access them from all modules?
A code sample would be great.
Thanks

1 Like

Hi,
To load resources you may use the Resources bean. See Resources - CUBA Platform. Developer’s Manual

Thanks. But where should I hold them in the project. in what path?

At any path you want. For example:
image

And then access the resource this way:

try (InputStream stream = resources.getResourceAsStream("com/company/sample/resources/pic.jpg")) {
// ...
} catch (IOException e) {
}
1 Like