How to Upload PDF File on Azure Blob Storage via Node.js?

Viewed 2110
  const blobServiceClient = await BlobServiceClient.fromConnectionString(connectionString);
  const containerClient = await blobServiceClient.getContainerClient(container);
  const blockBlobClient = containerClient.getBlockBlobClient(fileName);

  const uploadBlobResponse = await blockBlobClient.upload(content, content.length);
  console.log(uploadBlobResponse);
  console.log(`FIle upload successfully on cloud ${uploadBlobResponse.requestId}`);

i am trying like this, but blockBlobClient.upload() needs content, i converted file in base64 and sent it into content, but i am having issue, file is uplaoded but corrupted. any help please.

1 Answers

Check the SDK, the upload method construct is upload(HttpRequestBody, number, BlockBlobUploadOptions), the content is HttpRequestBody, check the parameter it requires

Blob, string, ArrayBuffer, ArrayBufferView or a function which returns a new Readable stream whose offset is from data source beginning.

So maybe you could try uploadFile, just use the file path to upload, I have tried this way it works.

Also, you could use uploadStream to upload the file readable stream.

Related