Azure-docs: Azure storage createBlockBlobFromLocalFile returns "Uncaught (in promise) TypeError: fs.stat is not a function"

Created on 26 Jun 2018  Â·  6Comments  Â·  Source: MicrosoftDocs/azure-docs

const path = require('path');
const storage = require('azure-storage');

const blobService = storage.createBlobService('Left out on purpose');
const containerName = 'test-container13';
const sourceFilePath = path.resolve('./attentto-logo.png');
const blobName = path.basename(sourceFilePath, path.extname(sourceFilePath));


exports.createContainer = function () {
  return new Promise((resolve, reject) => {
    blobService.createContainerIfNotExists(containerName, { publicAccessLevel: 'blob' }, err => {
      if (err) {
        reject(err);
      } else {
        resolve({ message: `Container '${containerName}' created` });
      }
    });
  });
};
exports.uploadImage = () => {
  return new Promise((resolve, reject) => {
    blobService.createBlockBlobFromLocalFile(containerName, blobName, sourceFilePath, err => {
      if (err) {
        reject(err);
      } else {
        resolve({ message: `Upload of '${blobName}' complete` });
      }
    });
  });
};

When calling the uploadImage function the code returns this error "Uncaught (in promise) TypeError: fs.stat is not a function"

I call it like this:

          fun.uploadImage().then((data)=>{
            console.log(data)
          });

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

cxp in-progress product-issue storagsvc triaged

Most helpful comment

@TravisCragg-MSFT Your link is dead. I am trying to use createBlockBlobFromLocalFile and I'm hitting this same error message. Do you have a simple example on how to do this from a react app?

All 6 comments

@knoerregaard Could you please post a link to the document you are referring to? These issues are designed for feedback about the content or questions about the product.

Hi and thanks for your reply. I followed these instructions here: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-nodejs

Hi again, My goal is actually to upload from browser - so I think that I am using the wrong API. Is it possible to use createBlockBlobFromBrowserFile instead? The application is a Meteor application.

@knoerregaard Here are the available functions inside blobService. There is no default way to upload a file from a URL. There are 2 ways to upload a file using this class, upload from a local file, or upload from a stream. You will most likely need to download the file locally first, or create a read stream from the URL.

If you would like this feature to be added, please submit your feedback Here.

We will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.

@TravisCragg-MSFT Your link is dead. I am trying to use createBlockBlobFromLocalFile and I'm hitting this same error message. Do you have a simple example on how to do this from a react app?

@Adam-Smith-MSFT can you help?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulmarshall picture paulmarshall  Â·  3Comments

mrdfuse picture mrdfuse  Â·  3Comments

Agazoth picture Agazoth  Â·  3Comments

jebeld17 picture jebeld17  Â·  3Comments

jharbieh picture jharbieh  Â·  3Comments