Getting url from FileRef

Hello JMix Team,

I need a help with getting a link from FileRef to use in my JavaScript component for <img src="" tag.

In my project there is an entity Employee and it has a FileRef field named image. Also I have integrated a third-party JavaScript library that is used to show organization tree charts, then I have created a custom JavaScript component for Jmix from this library.

Now I need to pass the json string with the names of employees, their positions and images of these employees to draw the chart.

The library requires URLs to be passed to draw images of employees, but I have difficulties with getting the urls from the employee’s image FileRef fields.

Thanks in advance.

Hi Tengiz,

I would suggest the following approach:

  • Create a custom REST controller that accepts an Employee identifier and returns its image. The controller could load the Employee entity, get its image from FileStorage and return it.
  • Perhaps the controller can allow anonymous access (see the docs), but then to load the Employee entity you should either use UnrestrictedDataManager or wrap your code in System Authentication.
  • In your org chart’s JSON, you could provide the image links like /api/empoyee-image/12345

Regards,
Konstantin