question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'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:

  1. Get an image buffer with canvas.toBuffer('image/jpeg')
  2. Set ops = { blobHTTPHeaders: { blobContentTypes: 'image/jpeg } }
  3. Call blockBlobClient.uploadData(imgBuffer, ops);

Expected behavior Blob is saved to storage.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
icanfathomcommented, Oct 4, 2022

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 calling new 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.

1reaction
xirzeccommented, Oct 4, 2022

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found