Using File and Image Data Type in Dataverse (Dynamics 365)


File Data Type was introduced somewhere around late 2019. At that time, it was only available for Canvas App and Power Automate / Flow, and with subsequent updates, it was then added for Model Driven App as well.

https://powerapps.microsoft.com/en-us/blog/introducing-improvements-to-data-storage-in-common-data-services/

The File Data type while creating the column à

By default, the file size is 32,768 KB.

  • Min – 1 KB
  • Maximum – 131072 KB

Let us keep it as 2000 KB and save it.

Here we have added the field in the form.

We need to save the record before the field is enabled.

On trying to upload a file more than 2000 KB size, the max size, we specified while creating the column, will give the below error.

“The upload failed for File Column 1. Please try again or contact your admin.”

The Maximum file size property cannot be updated after the column is created.

Similarly, we have the Image data type.

The default size is 10240 KB.

  • Min – 1 KB
  • Max – 30720 KB

If the image size is more than specified, we will get the below error message

The upload failed for Image Column 2. Please try again or contact your admin.

Below we have added a new file type column named File Column 2 with a maximum size of 100 MB.

With 2020 Release Wave 2, there is no need to specify file chunking while uploading a file of 16 MB or more, by dividing file data blocks of 4 MB or less through API.

https://docs.microsoft.com/en-gb/power-platform-release-plan/2020wave2/data-platform/improvements-microsoft-dataverse-file-image-upload-download

Earlier à

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/file-attributes#retrieve-file-data

Below is the sample code we have used to upload a file of size 86 MB.

The file uploaded à

Now let us look at downloading part.

The URL that can be used are

Byte Array formatà
https://%5Borganization%5D/api/data/v9.1/entitySetName(entityID)/fileTypeAttributeName/$value?size=full

Base64 String formatà

https://[organization]/api/data/v9.1/entitySetName(entityID)/fileTypeAttributeName/?size=full

Let us try the URL in the browser for both below File column 1 and 2.

https://pmaurya105.crm.dynamics.com/api/data/v9.1/crad3_sampletables(2d15b66a-a8b4-eb11-8236-000d3a1d5bf4)/crad3_filecolumn1/$value?size=full

It downloads the file for File Column 1à

In case of File Column 2, we get the below error message as its size exceeds 16 MB à

{“error”:{“code”:”0x80090001″,”message”:”Maximum file size supported for download is [16] MB. File of [84 MB] size may only be downloaded using staged chunk download.”}}

Base 64 Format ->

Below is the sample C# code to download the file if the size is less than 16 MB

If it is more than 16 MB we will get the below error à Request Entity Too Large

For Image Data Type, for uploading the full image > 16 MB (without dividing into a smaller chunk of less than 4 MB), we can use the below source code. It is the same as for the file data type.

For download, we can download either the thumbnail or full image (<= 16 MB) using the same source code used for file download.

For thumbnail –

GET [Organization URI]/api/data/v9.1/entity(recordGuid)/myentityimage/$value

For full image –

GET [Organization URI]/api/data/v9.1/entity(recordGuid)/myentityimage/$value?size=full

For more than 16 MB we need to use chunking.

Get all the details below à

https://jukkaniiranen.com/2019/12/why-would-you-store-images-and-files-in-cds/

https://debajmecrm.com/new-data-type-filein-cds-all-you-may-need-to-know-about-it/

https://debajmecrm.com/retrieve-contents-of-file-data-type-field-in-dynamics-365-cds-using-javascript-client-code/

Hope it helps..

Advertisements

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

One thought on “Using File and Image Data Type in Dataverse (Dynamics 365)”

Please share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.