web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Accessing file stored ...
Power Apps
Unanswered

Accessing file stored in Dataverse via Download() in Canvas app throws 401 error

(0) ShareShare
ReportReport
Posted on by 14

I have PDF files stored in a File Type column in Dataverse and trying to download those PDFs via a button/icon in Canvas app using 

Download("https://"&envURL&"/api/data/v9.0/<tablename>("&rowID&")/<columname>/$value")

 

It works for some users but for some it doesn't. If the users (for who it doesn't work) hit the env URL first ("https://org****.crm.dynamics.com") then the file download works for them too.

 

All users have same access to the table and column. This seems to be some API authorization issue which works when they get logged in to the environment but doesn't work otherwise.

 

Is there any solution to this?

I have the same question (0)
  • Verified answer
    v-xiaochen-msft Profile Picture
    on at

    Hi @nm14 ,

     

    This is the expected behavior. The API requires an access token to access it.

    If the user hits the env URL first, the access token will be generated automatically, so the Download function will work.

    As a workaround, please take a look at this blog.

    https://www.linkedin.com/pulse/download-dataverse-attachments-from-canvas-power-app-mesiha-p-eng/?trackingId=JDbShfb9Q2ScUjoH4DOzhg%3D%3D

     

    Best Regards,

    Wearsky

  • sudipm Profile Picture
    Microsoft Employee on at

    Hello @nm14 

    As user @v-xiaochen-msft has indicated in his answer this is expected, as that is direct api link you are trying to use, and doing so requires the user to have access to the table and logged into the model driven app before hand for the token to exist.

    Having said that there is probably no pure power app solution for your problem.

    You would need an intermediate web application. (Like Azure App Service)
    Your download link/button should pass the record id as url parameter to this intermediate web application
    The web app will authenticate the user (or perform SSO if user is already logged in) (check out Azure App service automatic authentication using Azure Entra (Azure AD))
    Then it will connect to dataverse and check the users access on the table/record using the id passed via url 
    If user has access to this record it will download the file column and pass the file as a file response to the user to enable his browser to start file download.

    You can find MS code sample to work with files here (check the download file method)
    https://github.com/microsoft/PowerApps-Samples/blob/master/dataverse/orgsvc/C%23-NETCore/FileOperations/Program.cs

    Apologies as I know you wanted a more simple answer or a direct plug and play or power automate solution, however none of those will work around authenticating and downloading file correctly and securely for the user. The solution above even though might sound complicated will work reliably and has no security gaps afaik.

    Update : While googling around a bit more for a more simpler solution, I found this blog post
    https://www.linkedin.com/pulse/download-dataverse-attachments-from-canvas-power-app-mesiha-p-eng/?trackingId=JDbShfb9Q2ScUjoH4DOzhg%3D%3D 

    I have not tried it, but it might be plausible this works in your case from the power app. Please try and post here for others if it works.

  • nm14 Profile Picture
    14 on at

    Thank you @v-xiaochen-msft , the solution mentioned in the blog worked!!

     

  • nm14 Profile Picture
    14 on at

    Thanks @sudipm , the solution mentioned in the blog post works!

  • sudipm Profile Picture
    Microsoft Employee on at

    @nm14 Great to hear that, I think @v-xiaochen-msft posted the link first to your post, pls mark his reply as the solution to help others.

  • Verified answer
    rbn_neu Profile Picture
    43 on at
    Just ran into this problem. Turning on a retired feature doesn't seem right. Any other solution in Power Platform  without custom development (just looking for any recent updates) ?
     
     
     
    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard