Reputation: 185
I am new to uploading files to blob storage and I need help for uploading video file to azure blob storage in nodejs. 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.
Please Help me out. Thanks
Upvotes: 1
Views: 2044
Reputation: 9950
You used fs.readfile()
function which wouldn't return a stream, thus raising your issue.
You could use fs.createReadStream()
function instead, and then you can use createWriteStreamToBlockBlob
to provide a stream to write to a block 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
}
}));
}
});
Upvotes: 1