简体   繁体   English

createBlobFromLocalFile 应该是一个非空字符串 - azure blob 存储

[英]createBlobFromLocalFile should be a non-empty string - azure blob storage

I'm trying to upload a file to azure blob storage.我正在尝试将文件上传到 azure blob 存储。 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!我在后端接收它,但我不断收到错误createBlobFromLocalFile should be a non-empty string我正在接收文件,正如您在控制台输出中看到的那样,但我不明白为什么我不能发送它到 blob 存储。我尝试用req.file, req,file.path, req.file.destination + filename替换名为blob string的第二个参数,但无法让它将文件存储在 blob 中。我感谢任何帮助!

app.js应用程序.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

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.根据documentation ,这应该是本地文件的路径(字符串值),而您将对象作为此参数的值传递。

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.但是,如果您使用file.path变量,它仍然无法工作,因为它告诉您本地计算机上的文件路径,而不是运行 Node.js 代码的服务器。 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.几天前我回答了一个问题,其中使用了formidable包来解析提取文件内容的请求。 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.虽然答案是针对较新版本的 SDK,但您可以使用它来查看服务器上的本地文件路径是如何被识别的。 You may find it useful: How to upload images and files to Azure Blob Node.js .您可能会发现它很有用: 如何将图像和文件上传到 Azure Blob Node.js。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:pchstr 必须是非空字符串 - TypeError: pchstr must be a non-empty string 非空字符串被转换为“假”值? - Non-empty string being converted to "falsy" value? 流星和Azure Blob存储 - Meteor and Azure Blob storage 错误:RangeError [MESSAGE_CONTENT_TYPE]:消息内容必须是非空字符串 - Error : RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty string Node.js TypeError:“file”参数必须是非空字符串 - Node.js TypeError: “file” argument must be a non-empty string 使用playStream()时,““ file”参数必须是非空字符串”错误 - '“file” argument must be a non-empty string' error when using playStream() 由于非空字符串错误,Discord.js 未发送嵌入 - Discord.js isnt sending the embed due to non-empty string error TypeError [ERR_INVALID_ARG_VALUE]:参数“id”必须是非空字符串。 已收到 '' - TypeError [ERR_INVALID_ARG_VALUE]: The argument 'id' must be a non-empty string. Received '' TypeError [ERR_INVALID_ARG_VALUE]:参数“id”必须是非空字符串。 收到''错误 - TypeError [ERR_INVALID_ARG_VALUE]: The argument 'id' must be a non-empty string. Received '' error 参数“documentPath”的值不是有效的资源路径。 路径必须是非空字符串 - Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM