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 : TOvE91klxuXrhbkRyzBG5Z
Power Pages - General Discussions
Unanswered

Error uploading to "File" column

Like (0) ShareShare
ReportReport
Posted on 24 Sep 2023 11:02:39 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:
  • fm_skeller Profile Picture
    277 Moderator on 30 Jan 2024 at 12:59:33
    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?

  • ansrikanth Profile Picture
    329 on 30 Jan 2024 at 11:14:19
    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 ...

  • KD-10121220-0 Profile Picture
    40 on 30 Jan 2024 at 09:49:13
    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

  • fm_skeller Profile Picture
    277 Moderator on 30 Jan 2024 at 09:12:36
    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.

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 60 Super User 2025 Season 2

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 2

#3
surya narayanan Profile Picture

surya narayanan 35

Loading complete