【发布时间】:2020-11-12 11:34:53
【问题描述】:
我是使用 azure blob sotorage 的新手,我希望在将图像保存到 azure blob 存储后返回其存储 url。
我的代码示例:
const uploadImage = catchAsync(async (req, res) => {
const blobName = getBlobName(req.file.originalname);
const stream = getStream(req.file.buffer);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
try {
await blockBlobClient.uploadStream(stream,
uploadOptions.bufferSize, uploadOptions.maxBuffers,
{ blobHTTPHeaders: { blobContentType: "image/jpeg" } });
res.send(httpStatus.OK, { message: 'File uploaded to Azure Blob storage.' });
} catch (err) {
throw new ApiError(httpStatus.NOT_FOUND, { message: err.message });
}
});
【问题讨论】:
标签: node.js azure-blob-storage