[英]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.