【发布时间】:2023-02-10 11:37:06
【问题描述】:
我正在尝试使用以下方法将图像/视频文件上传到 azure blob 存储 节点。但是在通过邮递员上传时我收到错误,即使 我可以在控制台中看到文件对象。下面是它的代码。
const addProductImage = async (req: any, res: Response) => { try { console.log(req.files.file); if (!req.files) { res.status(400).send({ status: Status.ERROR, error: "No file uploaded" }); } let file = req.files.file; const sharedKeyCred = new StorageSharedKeyCredential(accName, acckey) const blobServClient1 = new BlobServiceClient(`https://${accName}.blob.core.windows.net`, sharedKeyCred) const containerClient1 = blobServClient1.getContainerClient(containerName) const blockBlobClient = containerClient1.getBlockBlobClient(file.name); await blockBlobClient.upload(file, file.size); res.status(200).send({ status: Status.SUCCESS, }); } catch (error: any) { res.status(500).send({ status: Status.ERROR, error }); } }上面的代码控制台是 -
{ name: 'hclTech.png', data: <Buffer 81 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 02 7u 00 00 00 75 08 06 00 00 00 3f 4a 88 b4 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 00 07 ... 54120 more bytes>, size: 54170, encoding: '7bit', tempFilePath: '', truncated: false, mimetype: 'image/png', md5: 'd64ae80f1625e3c766b67bcf05a152a8', mv: [Function: mv] }在以“文件”为键的表单数据下在邮递员中上传文件 击中帖子,它给出了错误
【问题讨论】:
-
你能包括你在点击帖子时遇到的错误吗?
-
@Sridevi 捕获时出现 500 状态错误
标签: node.js azure express ecmascript-6 azure-blob-storage