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

Osama Abid :
  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.

George Chen :

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.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=376642&siteId=1