js-sdk
js-sdk copied to clipboard
Cannot get binary files when using the azure blob storage binding
Expected Behavior
Using the following code I would except to either receive a buffer or a base64 encoded string.
const result = await client.binding.send('filestore', 'get', null, { blobName: filename });
console.log(typeof result); // string
const buffer = Buffer.from(result, 'base64');
Actual Behavior
What you actually get is a mangled string that is a binary stream converted to text and then parsed as JSON.
Steps to Reproduce the Problem
- Create a
bindings.azure.blobstorage
binding and setdecodeBase64
totrue
. - Upload a file where
data
is a Buffer
const base64Data = data.toString('base64');
const meta = {
blobName: fileName,
"contentType" : contentType ?? 'application/octet-stream',
"contentDisposition" : "attachment",
"cacheControl" : "no-cache",
"custom" : "hello-world"
};
const response = await client.binding.send(Bindings.fileStore, 'create', base64Data, meta);
- Get the file back and save it to disk