【发布时间】:2021-12-05 11:04:35
【问题描述】:
下面的代码允许使用 node.js 'azure-storage' 包从 Azure-Storage 流式传输视频。
我想实现相同的目标,但要使用 '@azure/storage-blob' 包。
.....
app.get("/video", (req, res) => {
const videoPath = req.query.path;
const blobService = createBlobService();
const containerName = "videos";
blobService.getBlobProperties(containerName, videoPath, (err, properties) => {
if (err) {
console.error(`Error occurred getting properties for video ${containerName}/${videoPath}.`);
console.error(err && err.stack || err);
res.sendStatus(500);
return;
}
// Writes HTTP headers to the response.
res.writeHead(200, {
"Content-Length": properties.contentLength,
"Content-Type": "video/mp4",
});
// Streams the video from Azure storage to the response.
blobService.getBlobToStream(containerName, videoPath, res, err => {
if (err) {
console.error(`Error occurred getting video ${containerName}/${videoPath} to stream.`);
console.error(err && err.stack || err);
res.sendStatus(500);
return;
}
});
});
});
app.listen(PORT, () => {
console.log(`.....`);
});
提前致谢...
【问题讨论】:
标签: node.js azure express video-streaming azure-storage