[英]Uploading Video File to AZURE BLOB STORAGE in NODEJS
I am new to uploading files to blob storage and I need help for uploading video file to azure blob storage in nodejs. 我是将文件上传到Blob存储的新手,我需要将视频文件上传到Node.js中的Azure Blob存储的帮助。 I have done a bit of code for this service.
我为此服务做了一些代码。
here is my service code snippet 这是我的服务代码段
uploadCourseVideo.post(multipartMiddleware, function (req, res) {
var dataStream;
console.log(req.body, req.files);
fs.readFile(req.files.file.path, function (err, dataStream) {
var blobSvc = azure.createBlobService('ariasuniversity', 'account key');
blobSvc.createContainerIfNotExists('elmsvideos', function (error, result, response) {
if (!error) {
// Container exists and is private
blobSvc.createBlockBlobFromStream('elmsvideos', 'myblob', dataStream, dataStream.length, function (error, result, response) {
if (!error) {
// file uploaded
}
});
}
});
});`
The error which I am getting is of Stream.pause() is not a function. 我收到的错误是Stream.pause()不是函数。
Please Help me out. 请帮帮我。 Thanks
谢谢
You used fs.readfile()
function which wouldn't return a stream, thus raising your issue. 您使用了
fs.readfile()
函数,该函数不会返回流,因此会引发问题。 You could use fs.createReadStream()
function instead, and then you can use createWriteStreamToBlockBlob
to provide a stream to write to a block blob. 您可以改为使用
fs.createReadStream()
函数,然后可以使用createWriteStreamToBlockBlob
提供要写入块Blob的流。
var readStream = fs.createReadStream(req.files.file.path);
var blobSvc = azure.createBlobService('ariasuniversity', 'account key');
blobSvc.createContainerIfNotExists('elmsvideos', function (error, result, response) {
if (!error) {
// Container exists and is private
readStream.pipe(blobSvc.createWriteStreamToBlockBlob('elmsvideos', 'myblob', function (error, result, response) {
if(!error) {
// file uploaded
}
}));
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.