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.

Upload blob runtime error

See original GitHub issue
  • Package Name: @azure/storage-blob
  • Package Version: ^12.10.0
  • Operating system: Ubuntu 20.04.4 LTS
  • nodejs
    • version: v14.18.2
  • browser
    • name/version:
  • typescript
    • version:
  • Is the bug related to documentation in

Describe the bug Got error Error: body must be a string, Blob, ArrayBuffer, ArrayBufferView, or a function returning NodeJS.ReadableStream. Although console.log(`blob instanceof Blob: ${blob instanceof Blob}`); outputs blob instanceof Blob: true, and console.log(blob); output Blob { size: 22, type: 'application/json' } To Reproduce Run following code using node index.js. index.js:

const connStr = ".....";
const { BlobServiceClient } = require("@azure/storage-blob");
const { performance } = require('perf_hooks');
const { Blob } = require('buffer');

const blobServiceClient = BlobServiceClient.fromConnectionString(connStr);

const containerName = "newcontainer1653680240090";
async function main() {
    const start = performance.now();
    const containerClient = blobServiceClient.getContainerClient(containerName);
    const obj = { hello: 'world' };
    const blob = new Blob([JSON.stringify(obj, null, 2)], { type: 'application/json' });
    console.log(`blob instanceof Blob: ${blob instanceof Blob}`);
    console.log(blob);
    const blobName = "newblob" + new Date().getTime();
    const blockBlobClient = containerClient.getBlockBlobClient(blobName);
    await blockBlobClient.upload(blob, blob.size);
    console.log(performance.now() - start);
}

main();

Sample package.json:

{
  "name": "AzureBlobTest",
  "version": "1.0.0",
  "description": "performance test",
  "main": "index.js",
  "author": "Xin Zhang",
  "license": "MIT",
  "dependencies": {
    "@azure/storage-blob": "^12.10.0"
  }
}

Expected behavior The blob should be uploaded without error

Screenshots image

Additional context N/A

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
zhangxin511commented, May 31, 2022

@xirzec Thanks for replying. I was trying to get some performance analysis for request body using different types between string, stream, ArrayBuffer, blob and noticed this.

If I read the code correctly, eventually everything was serialized to string so using a string body is most efficient, especially the item I want to save is already a string?

0reactions
xirzeccommented, May 31, 2022

This error is from core-http. We might need some fix in core as well. https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-http/src/serializer.ts#L425

Since the check given is typeof Blob === "function" || typeof Blob === "object") && value instanceof Blob) perhaps you could cheese the logic by making the constructor global? Something like global.Blob = Blob ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure blob storage upload fail - Microsoft Q&A
Uploading files to blob endpoint Azure storage account via Storage Explorer and command line is failing with error "Response Status: 403 ...
Read more >
Failed to upload file Standard_Error_Output.log to Blob ...
Getting the below given error on the release Pipeline, in the Visual Studio Test Task, This is executing on a self hosted agent...
Read more >
Unable to upload/download blob storage to container from ...
However, when I run the same thing from visual studio (local) I get error at uploading file to blob storage. Microsoft.Azure.Storage.
Read more >
Azure Blob Upload Task error – SQLServerCentral Forums
Azure Blob Upload Task error ... Hi,. I am trying to understand an SSIS package where a previous employee who left has written...
Read more >
REIM_FIXED_DEAL_UPLOAD_J...
REIM_FIXED_DEAL_UPLOAD_JOB is failing with below error: Runtime : Fixed Deals Upload work 100 failed with error: Cannot build a blob from a ...
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