Assign an image to an Entity

Assign an image to an Entity

  

I have a picture entity, imported from the base entity in the Advanced menu of the entity.

The picture entity contains the Id of the base entity, the Picture (binary), a Filename and a Filetype.

In the Interface-tab under Images I have uploaded some pictures.

Now I want to assign these pictures in a program (used for bootstrap) to the appropriate records of the base entity. So first I retrieve the Id of the base entity and then I want to assign the picture to the Picture attribute.

How can I do this? The image has a logical name and a Runtime Path. Is there a function to "load" the image as binary data that I can assign to the Picture attribute?

Best Regards,

Peter Nijhuis

Solution

Hello Peter,

One alternative is to upload your pictures as Resources ("Data" tab). You'll then have direct access to them as binary data variables, so your assignment's Value would look something like this: Resources.MyImage.

Solution

Hello Aurelio,

With Resources it's a piece of cake.
Thanks a lot!

Best Regards,

Peter.


Aurelio Santos wrote:

Hello Peter,

One alternative is to upload your pictures as Resources ("Data" tab). You'll then have direct access to them as binary data variables, so your assignment's Value would look something like this: Resources.MyImage.



Is this a solution for web apps only?? I am developing a mobile app and try to follow Aurelio’s instruction, I.e. uploading my image files as resources and then trying to assign them to a local variable of type binary. However, when my uploaded resource is an image (.png in my case), the resource is not shown as an option in the assignment. Any other solution for this problem? Thanks!

Hi Denis,

Sorry for the delayed reply.

This happens because resources are stored server side, so you don't have direct access to them in your client actions.

If you really want to use resources, you can create a server action that returns the resource, and then invoke that server action in your client-side code. This will, obviously, result in an additional call to the server, so latency might be a concern.

Thanks Aurelio, I used the web-Filesystem extension, i.e. server action Path_GetApplicationDirectory to find where the resource is deployed and File_ReadBinary to read the binary content of the image. It is a bit cumbersome to simply assign an image to a binary variable, but it works.