cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
SamPo Impactful Individual
Impactful Individual

Download link for CDS attachments

Hi,

 

I have an entity with attachments (stored in notes).

For now I've been using the attachments control in a gallery to download each file but this has limitations on styling and layout.

Instead I've created a new gallery which shows the name and thumbnail for each attachment and now I want to see if there is a way to recreate the download feature. I know there is a download function but I need a URL for each file.

 

Does anyone know how I can get/build a URL which will download a specific file stored in CDS attachments?

 

Thanks

Sam

1 ACCEPTED SOLUTION

Accepted Solutions
EricRegnier Impactful Individual
Impactful Individual

Re: Download link for CDS attachments

The Download function requires a url to a remote file. The API call returns the body as base 64 string and a filename. It's not the actual URL to a file that the Download function expects. I'm not sure you can stream the file on a canvas app directly. Not ideal, but you'll have to call some kind of web service (like Azure Function) to get the file or another option is with Power Automate that saves the file to a temp location and returns in the response the location of the file.

If those two options are not feasible, you might have to rethink about saving the files directly in CDS (which is quite costly btw) and store those in blob storage or SharePoint for example.

Hope this clarifies a little....

View solution in original post

4 REPLIES 4
EricRegnier Impactful Individual
Impactful Individual

Re: Download link for CDS attachments

Hi @SamPo,

You can download the note's attachment via the CDS Rest API directly from the annotation (note) entity. Here's the documentation:

https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/reference/entities/annotati...

For example: https://<org>.api.crm.dynamics.com/api/data/v9.1/annotations(b06b2a59-9e23-4e6b-9dd7-98510563b6fa)?$...

 

Hope this helps!

SamPo Impactful Individual
Impactful Individual

Re: Download link for CDS attachments

Hi @EricRegnier 

 

Thanks for this! I've managed to use the link to successfully pull the info of the file but when I click the URL it's only showing me the JSON response of the API call in the browser. The question is how do I make this link actually download the file to my PC?

 

2020-05-20_0949.png

 

This is what I have now from the app. Again the info it returns is correct but it just opens up a browser window with the response and doesn't actually save the file.

 

Any ideas?

 

Thanks

Sam

EricRegnier Impactful Individual
Impactful Individual

Re: Download link for CDS attachments

The Download function requires a url to a remote file. The API call returns the body as base 64 string and a filename. It's not the actual URL to a file that the Download function expects. I'm not sure you can stream the file on a canvas app directly. Not ideal, but you'll have to call some kind of web service (like Azure Function) to get the file or another option is with Power Automate that saves the file to a temp location and returns in the response the location of the file.

If those two options are not feasible, you might have to rethink about saving the files directly in CDS (which is quite costly btw) and store those in blob storage or SharePoint for example.

Hope this clarifies a little....

View solution in original post

SamPo Impactful Individual
Impactful Individual

Re: Download link for CDS attachments

Got it.

 

Thanks for the advise, I think I might reconsider where I save these files. Just wanted everything to be neatly stored in CDS but seems like it might not be the best option.

 

Thanks

Sam

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Users online (8,380)