0

I am using createBlockBlobFromLocalFile() function to upload the file to azure-storage. Here is the code,

var azureStorage = require('azure-storage');
var blobUri = "http://accountname.blob.core.windows.net";
var blobService = azureStorage.createBlobServiceWithSas(blobUri, sasKey).withFilter(new azureStorage.ExponentialRetryPolicyFilter());
blobService.createBlockBlobFromLocalFile('container', 'taskblob', 'task1.txt', function(error, result, response) {
        if (!error) {
            console.log("uploaded");
        } else {
            console.log(error);
        }
      }); 

when i run the above code i am getting error like

events.js:183 throw er; // Unhandled 'error' event ^

Error: ENOENT: no such file or directory, read

My file path and code are in same folder like

D:\path\upload.js

D:\path\task1.txt

I checked the file availability using below code, it returns as success,

var fs = require('fs');
if (fs.existsSync('task1.txt')) { }

Please someone suggest me a solution for this,

UPDATE : Error message is different from this question

skr07
  • 707
  • 1
  • 10
  • 36
  • Have you tried passing the absolute path? – Arash Motamedi Mar 05 '18 at 07:40
  • yes i tried absolute path also like `blobService.createBlockBlobFromLocalFile('container', 'taskblob', 'D:\path\task1.txt', function(error, result, response) { }` but not working. still the same error – skr07 Mar 05 '18 at 07:41
  • i also tried `var path = require('path'); path.join(__dirname, 'task1.txt')` – skr07 Mar 05 '18 at 07:45
  • Possible duplicate of [azure createBlockBlobFromLocalFile shows no such file or directory](https://stackoverflow.com/questions/49050378/azure-createblockblobfromlocalfile-shows-no-such-file-or-directory) – Aaron Chen Mar 06 '18 at 09:22

1 Answers1

0

Do you have read permission to that file? You can test it such as by creating a file read stream to read the file content.

I tested following code with azure-storage-node@2.8.0, and it works well.

var blobService = azureStorage.createBlobService(accountName, sasKey).withFilter(new azureStorage.ExponentialRetryPolicyFilter());

blobService.createContainerIfNotExists('mycontainer', function (err, res) {
  if (!err) {
    blobService.createBlockBlobFromLocalFile('mycontainer', 'taskblob', 'task1.txt', function (error, result, response) {
      if (!error) {
          console.log("uploaded");
      } else {
          console.log(error);
      }
    }); 
  }
});