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!
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);
}
});
}
@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?
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 ...
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
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.
Lucas001
60
Super User 2025 Season 2
Fubar
55
Super User 2025 Season 2
surya narayanan
35