'The first argument must be an instance of Buffer' with valid buffer when calling uploadData()
See original GitHub issue- azure/storage-blob:
- 12.11.0
- Operating system:
- nodejs
- 16.13.0
- typescript
- 4.6.3
Describe the bug Similar to https://github.com/Azure/azure-sdk-for-js/issues/22534. But I updated to the latest release (@azure/storage-blob@12.11.0) and it’s still failing. I’m also not trying to read any data; just uploading.
The error I get is
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
My code looks like:
await blockBlobClient.uploadData(imgBuffer, {
blobHTTPHeaders: {
blobContentType: 'image/jpeg',
},
});
I verified that imgBuffer is a valid buffer with image content (created with canvas.toBuffer('image/jpeg')
).
I’m wondering if providing blobHTTPHeaders but NOT including blobContentMD5
among them is causing problems?
To Reproduce Steps to reproduce the behavior:
- Get an image buffer with
canvas.toBuffer('image/jpeg')
- Set
ops = { blobHTTPHeaders: { blobContentTypes: 'image/jpeg } }
- Call
blockBlobClient.uploadData(imgBuffer, ops);
Expected behavior Blob is saved to storage.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
node.js - nodejs - first argument must be a string or Buffer
So I am assuming, by the time the callback is executed the res.end() might get called. Try closing the request within the callback....
Read more >REGL API
The arguments to the update pathway are the same as the constructor and the returned value will be a reference to the buffer....
Read more >the "path" argument must be of type string or an instance of buffer or ...
png" async function uploadFile() { const metadata = { metadata: { // This line is very important. It's to create a download token....
Read more >Vert.x Core Manual
You may have heard of this before - for example Node.js implements this ... The first argument to these methods is an index...
Read more >nodejs read binary file into buffer - Industry Today
Buffer.allocUnsafe() but ensures that the newly created Buffer instance ... you first need to create a form and append the file to it....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Friends.
I am the worst.
I refactored my project and forgot to put my new connection keys into local.settings.json. So that was the problem. I was passing in
undefined
for accountName, accountKey when callingnew StorageSharedKeyCredential()
.I suppose it would be nice to get a more helpful error message in this case. But I leave that up to your (clearly) more capable minds.
@EmmaZhu Feel free to close this if desired.
@icanfathom I have made more and sillier mistakes! Please don’t feel bad. I’m very happy you were able to get to the bottom of your trouble.
@EmmaZhu perhaps putting some runtime checks into
StorageSharedKeyCredential
would be useful, since it shouldn’t get run very often?