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

Community site session details

Session Id :
Power Pages - General Discussions
Unanswered

Error uploading to "File" column

(0) ShareShare
ReportReport
Posted on by 40

I always get the same error when uploading a file to a "File" column.

 

Steps:

- User attaches file to multi-step form (Entity A) <--- this creates an annotation with the file

- Portal Web API creates multiple related records (Entity B) <--- this has file column

- Portal Web API retrieves file from the annotation record linked to entity A

- Portal Web API tries to update entity B with the file!

 

DominoSeer_0-1695552110060.png

 

Obviously I have site settings and table permissions as I can create/retrieve/modify via API for all entities.

 

I have tried constructing the API call with Dataverse REST Builder (which also errors if you try and execute in the tool).

 

I get :

"message": "Error identified in Payload provided by the user for Entity :''

InnerException : System.ArgumentException: Stream was not readable.\r\n at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, 

 

I have googled Base64 vs Binary vs everything else I can think of...

 

I haven't tried to use power automate instead, by hooking into the multistep session and doing it via submit there.

 

 

function updateAppointmentRequestFile(appointmentRequestId, fileName, binaryData) {

 const base64String = binaryData;

 // Decode the Base64 string into a binary string
 const binaryString = atob(base64String);

 // Convert the binary string into a byte array
 const byteArray = new Uint8Array(binaryString.length);
 for (let i = 0; i < binaryString.length; i++) {
 byteArray[i] = binaryString.charCodeAt(i);
 }

 console.log(byteArray);
 console.log("Uploading file to appointment request letter...");

 webapi.safeAjax({
 type: "PUT",
 url: "/_api/hf_appointmentrequests(" + appointmentRequestId + ")/hf_letter?x-ms-file-name=" + encodeURIComponent(fileName),
 contentType: 'application/octet-stream',
 data: byteArray,
 processData: false, // Prevent processing the data
 success: function (res, status, xhr) {
 console.log("File attribute updated successfully");
 },
 error: function (res, status, xhr) {
 console.log(xhr);
 }
 });
}

 

 

 

Categories:
I have the same question (0)
  • fm_skeller Profile Picture
    277 Moderator on at
    Re: Error uploading to "File" column

    I am curious as to why you are moving the file from entity A to all linked entity B records - and especially using the portal web api? Would it not be easier to use a cloudflow or plugin to handle this? In addition - the way you are describing the process it creates multiple copies of the file which seems a bit redundant.
    On topic, I'll see if I can get it to work with just the power pages webapi and get back to you.

  • KD-10121220-0 Profile Picture
    40 on at
    Re: Error uploading to "File" column

    It does create multiple copies and deliberately so as this is a "transactional" website, where you submit a request and up to 5 very separate people could "bid" for the work.

     

    The issue was extremely hard to track down, but there is a partner out there that came across this issue before and blogged about it.

     

    The solution is using the metadata browser to get the attribute name:

    https://<yourdomain>.crm4.dynamics.com/api/data/v9.1/$metadata

  • ansrikanth Profile Picture
    329 on at
    Re: Error uploading to "File" column

    I was wondering why cant you go with some sort of cloud flow and off load the load from power pages ? like how the other @fm_skeller mentioned ...

  • fm_skeller Profile Picture
    277 Moderator on at
    Re: Error uploading to "File" column

    @DominoSeer would you mind sharing the link to the blog? Might be good for future reference. 
    Also, to be sure, as I am curious, the code you posted works if you supply the correct fieldname - and it's not the schema name? Or am I misinterpreting your explanation?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Pages

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 45 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 43

#3
Fubar Profile Picture

Fubar 42 Super User 2025 Season 2

Last 30 days Overall leaderboard