akki_2891
akki_2891

Reputation: 516

Download/Upload file from AzureBlob to Nodejs server

I want to download a file from Azure blob storage to Nodejs server file system,do some processing on that file on Nodejs side and upload the updated copy of file to the Blob storage again from the file system.

Please suggest some way/or anyone has implemented the same.

Thanks :)

Upvotes: 0

Views: 2671

Answers (1)

Downloading a Blob using Node.js:

  • getBlobToFile - writes the blob contents to file
  • getBlobToStream - writes the blob contents to a stream
  • getBlobToText - writes the blob contents to a string
  • createReadStream - provides a stream to read from the blob

The following example demonstrates using getBlobToStream to download the contents of the myblob blob and store it to the output.txt file using a stream:

var fs = require('fs');
blobSvc.getBlobToStream('mycontainer', 'myblob', fs.createWriteStream('output.txt'), function(error, result, response){
  if(!error){
    // blob retrieved
  }
});

Upload a file

How to: Upload a blob into a container

A blob can be either block, or page based. Block blobs allow you to more efficiently upload large data, while page blobs are optimized for read/write operations. For more information, see Understanding block blobs and page blobs.

Block blobs

To upload data to a block blob, use the following:

  • createBlockBlobFromLocalFile - creates a new block blob and uploads the contents of a file.
  • createBlockBlobFromStream - creates a new block blob and uploads the contents of a stream.
  • createBlockBlobFromText - creates a new block blob and uploads the contents of a string.
  • createWriteStreamToBlockBlob - provides a write stream to a block blob.

The following example uploads the contents of the test.txt file into myblob.

blobSvc.createBlockBlobFromLocalFile('mycontainer', 'myblob', 'test.txt', function(error, result, response){
  if(!error){
    // file uploaded
  }
});

Upvotes: 2

Related Questions