简体   繁体   中英

Error: ENOENT: no such file or directory, read

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

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);
      }
    }); 
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM