0
votes

I'm trying to upload a file to azure blob storage. I'm receiving it on the backend, but I keep getting the error createBlobFromLocalFile should be a non-empty string I"m receiving the file as you can see in console output, but I don't understand why I can't send it to blob storage. I've tried replacing the second parameter called blob string with req.file, req,file.path, req.file.destination + filename, but haven't been able to get it to store the file in blob. I appreciate any help!

app.js

app.post("/api/fileupload", checkAuth, upload, (req, res, next) => {

  console.log("req.file below");
  console.log(req.file);

  blobService.createBlockBlobFromLocalFile('testcontainer', req.file, "image.png", function (error, result, response) {
    console.log(response);
    if (!error) {
      // file uploaded
    }
  });

});

Console Output

req.file below
{ fieldname: 'file',
  originalname: 'blob',
  encoding: '7bit',
  mimetype: 'image/jpeg',
  destination: 'public/uploads/',
  filename: '18af517e9a94b2bdab02c7169b8b88a7',
  path: 'public\\uploads\\18af517e9a94b2bdab02c7169b8b88a7',
  size: 39367 }
TypeError: Parameter blob for function _createBlobFromLocalFile should be a non-empty string
1

1 Answers

0
votes

Based on the documentation, this should be the path of the local file (a string value) whereas you're passing an object as value of this parameter.

However, if you use file.path variable, it would still not work as it tells you the path of the file on the local computer and not the server on which your Node.js code is running. You will need to specify the path of the file on the server.

I answered a question just a few days ago where formidable package was used to parse the request to extract the file content. Though the answer is for the newer version of the SDK but you can use that to see how local file path on the server was identified. You may find it useful: How to upload images and files to Azure Blob Node.js.