cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jonathanhotono
Regular Visitor

Power Portal Web API get file/image /$value issue

I am just testing to use the Web API to download image from dataverse.

 

Web API below would download a corrupt file instead of the correct image file uploaded into the dataverse table entry. It is already configured to have GLOBAL table permission with read access for everyone including anonymous users, with site settings applied.

https://[PORTALURL].powerappsportals.com/_api/accounts(7f240c9e-1d74-ec11-8943-00224812ee84)/entityimage/$value

 

However dynamics web api below would correctly download the image file:

https://[ORG].crm6.dynamics.com/api/data/v9.1/accounts(7f240c9e-1d74-ec11-8943-00224812ee84)/entityimage/$value   

 

I am not sure where I should report this issue but it is definitely becoming an issue when trying to render image/download files directly. I cannot use the dynamics web api url since it is not available for anonymous users to consume (requirement)

 

1 ACCEPTED SOLUTION

Accepted Solutions
GuidoPreite
Super User
Super User

@jonathanhotono 

I got this link that is very related to the issue you are facing:

https://docs.microsoft.com/en-us/power-platform-release-plan/2022wave1/power-apps-portals/portals-su...

It's a planned feature and is written: "A user can download the image directly from portal forms or with the portals Web API." so probably when this feature will be implemented you will not face the issue, meanwhile the only alternative is the javascript.

hope it helps

View solution in original post

8 REPLIES 8
GuidoPreite
Super User
Super User

are you using a direct link to download it or a javascript code? if is a javascript code can you share it?

Usually there are problems to upload an image to that kind of fields (due to javascript enconding) but being a download a GET request you should not have

I am using direct link to download it, for images if you do:

<img src="https://[ORG].crm6.dynamics.com/api/data/v9.1/accounts(7f240c9e-1d74-ec11-8943-00224812ee84)/entityimage/$value" /> --> this will render correct image

 

<img src="https://[PORTALURL].powerappsportals.com/_api/accounts(7f240c9e-1d74-ec11-8943-00224812ee84)/entityimage/$value" />  --> broken image will be rendered

 

If you go to https://[PORTALURL].powerappsportals.com/_api/accounts(7f240c9e-1d74-ec11-8943-00224812ee84)/entityimage without $value, correct base64 string will be returned but it would not be ideal to render the image directly on site as I will have to write a JS function to render the image.

GuidoPreite
Super User
Super User

thanks for the reply. The syntax with and without $value works with all the columns, if for example instead of entityimage you put name you will get the name of the account.

Probably the fact $value is not working correctly has to do with the MS implementation of the _api endpoint (I imagine that with the standard endpoint it returns the blob, with _api endpoint it returns the base64 value and see the broken one), more than opening a ticket to solve this specific issue you can't do I am afraid.

Writing a js function to render the image would not be difficult (as many browsers can render the base64 encoding if the proper start tag is written inside the src), but it will require you to get the base64 first inside a jquery call first.

Thanks. Yes correct. When you go directly to /$value, it actually downloads corrupt $value (utf-8) file.

jonathanhotono_0-1645864700456.png

 

If you perform an http request into https://[PORTALURL].powerappsportals.com/_api/accounts(7f240c9e-1d74-ec11-8943-00224812ee84)/entityimage it would return something like below, which I will need to write a JS function to perform the request, get the value and render into the src tag.

{
  "@odata.context": "https://xxx.powerappsportals.com/_api/$metadata#accounts(7f240c9e-1d74-ec11-8943-00224812ee84)/entityimage",
  "value": "iVBORw0KGgoAAAA...."
}

This is definitely a bug that I will need to raise to microsoft however I am not sure where to raise as normal tickets would probably just be ignored (reason as always, API is not within their area of support).

GuidoPreite
Super User
Super User

@jonathanhotono 

I got this link that is very related to the issue you are facing:

https://docs.microsoft.com/en-us/power-platform-release-plan/2022wave1/power-apps-portals/portals-su...

It's a planned feature and is written: "A user can download the image directly from portal forms or with the portals Web API." so probably when this feature will be implemented you will not face the issue, meanwhile the only alternative is the javascript.

hope it helps

Django
MVP

A colleague of mine got this working with JavaScript using two different endpoints:

Get file

 
Get file content:
these are two different ways to reach the same end point… in this preview period we are using the combined endpoints to
provide a file download experience.

Thanks! Unfortunately the url is trimmed, are you able to post just the url strings?

 

Update:

https://[PORTALURL].powerappsportals.com/_api/accounts([INTERNAL_ID])/entityimage?size=full --> it displays the JSON result with value as base64. If we have lots of images there will be a performance overhead to get the value and then JS will set the img src. 

 

I guess as GuidoPreite  mentioned, I'll either raise this as an issue with support or just wait until endpoint below is fixed and spits out the correct file.

https://[PORTALURL].powerappsportals.com/_api/accounts([INTERNAL_ID])/entityimage/$value?size=full 

Sorry! The mobile experience of this forum is killing me...

 

Get file
[PORTALURL].powerappsportals.com/_api/[ENTITY INTERNAL NAME IN PLURAL]/?fetchXml=<fetch mapping="logical" output-format="xml-platform" version="1.0" distinct="false"><entity name="[ENTITY INTERNAL NAME]"> <attribute name="[NEW FILE TYPE COLUMN INTERNAL NAME]" /> <filter> <condition attribute="[ENTITY ID COLUMN INTERNAL NAME]" operator="eq" value="ef4c3329-6262-ec11-8f8f-000d3a2d17b3" /> </filter> </entity></fetch>
 
Get file content:

[PORTALURL].powerappsportals.com/_api/[ENTITY INTERNAL NAME IN PLURAL](ef4c3329-6262-ec11-8f8f-000d3a2d17b3)/[NEW FILE TYPE COLUMN INTERNAL NAME]?size=full

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (3,226)