I have a url with a SAS token to upload a file. I have a base64 string of a previously defined content type that I need to upload.
import { FileUploadStreamOptions, ShareFileClient } from "@azure/storage-file-share";
import { Readable } from "readable-stream";
async submitData(context: ComponentFramework.Context<IInputs>, fileName: string, ext: string, base64: string, contentType: string, classification: string, upload: any) : Promise<boolean> {
const buffer = Buffer.from(base64, 'base64');
let client = new ShareFileClient(upload.url);
let readable = Readable.from(buffer);
const options = {
fileHttpHeaders: {
fileContentType: contentType,
},
};
await client.uploadStream(readable, buffer.length, 4 * 1024 * 1024, 5, options);
console.log("Upload successful");
// more logic
return true;
}
I’m having two problems with this code:
-
The
await client.uploadStream(readable, buffer.length, 4 * 1024 * 1024, 5, options);
is not being awaited and the method is escaped. -
The uploaded file is corrupted. When downloaded, the content comes back as:
{"$content-type":"application/pdf","$content":"AAAAAAAAAAAAAA...AAAAA"}
-
I have tried not awaiting the call and that seems to work for the most part although it really should be awaited.
-
I tried adding encoding to the stream but that didn’t seem to work either.