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);
}
});
}