How to Store Publicly Accessible Images on a Dynamics 365 record

Adam Murchison, 18 February 2021

When storing an image on a record, one might think to create a field that has an ‘image’ type as seen below.

image

This is useful, but when retrieving this image through an API request you’ll be sent base64 and a link to the image with the suffix ‘.download.aspx’ which for some isn’t ideal.

The workaround here is to take a leaf out of the book of the implementation in the Dynamics for Marketing module. Just like how they implemented Hero Image/Card image hosting on an Event record, you can replicate this on any entity. The interface to upload images can be seen below:

image

Disclaimer:

To use the custom control that sits on the field you will need the Dynamics for Marketing module. This will include the entity ‘File’, schema name = ‘msdyncrm_file’.

Backend:

First off, we create a lookup field to the entity of ‘File’. This entity has a URL field which you can use to retrieve the byte array for the image.

image

On the file record:

image

Frontend:

Next, to implement a more friendly interface we can use their control on the File lookup field. This is done by changing the properties of the field as below:

image

Summary:

You now have a great front-end display of an image gallery and also a way to store images as a byte array in the back end.