【发布时间】:2020-12-01 22:16:10
【问题描述】:
我正在尝试将多张图片上传到 azure blob 服务,一切看起来都很好,尽管我错过了一些东西 我得到的错误
events.js:292 投掷者; // 未处理的“错误”事件 ^
错误:ENOENT:没有这样的文件或目录,打开“logo192.png” ReadStream 实例上的“错误”事件: 在内部/fs/streams.js:163:14 在 FSReqCallback.oncomplete (fs.js:159:23) { errno: -2, code: 'ENOENT', syscall: 'open', path: 'logo192.png' }
const uuidv1 = require("uuid/v1");
var azure = require("azure-storage");
var fs = require("fs");
const containerName = "image";
const fileUpload = async (req, res, next) => {
let imageStatus = [];
console.log(req.files);
await req.files.forEach((reqfile, i) => {
const blobName = uuidv1() + "-" + reqfile.originalname;
const blobSvc = azure.createBlobService();
const file = reqfile.originalname;
const stream = fs.createReadStream(file).pipe(blobSvc.createWriteStreamToBlockBlob(containerName, blobName, { blockIdPrefix: "block" }));
let dataLength = 0;
stream
.on("data", function (chunk) {
dataLength += chunk.length;
})
.on("end", function () {
console.log("The length was:", dataLength);
});
blobSvc.createBlockBlobFromStream(containerName, blobName, stream, dataLength, function (error, result, response) {
if (!error) {
console.log("ok Blob uploaded");
imageStatus.push({
imageName: result.name,
imagePath: result.name,
});
} else {
console.log(error);
}
});
});
res.status(200).json({ imageStatus });
};
module.exports = fileUpload;
req.files 的控制台输出
[
{
fieldname: 'files',
originalname: 'logo192.png',
encoding: '7bit',
mimetype: 'image/png',
buffer: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 c0 00 00 00 c0 08 03 00 00 00 65 02 9c 35 00 00 00 87 50 4c 54 45 00 00 00 64 da fb 61 da fc ... 5297 more bytes>,
size: 5347
}
]
【问题讨论】:
标签: node.js filesystems azure-blob-storage