简体   繁体   中英

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. 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

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
            }
        }));

    }
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM