node.js - Node JS Request + Express Pipe -


i have problem streaming video files server another.

i wrote script

var request = require("request"),     express = require("express");  var app = express();  app.get("/cast", function(req, res) {      var url = req.query.video;      res.writehead(200, {         'content-type': 'video/mp4'     });      request({         url: url,         headers: {             referer: "http://example.com/1706398/" + url         }     })         .on('response', function(response) {              response.on('data', function(data) {                 console.log("data chunk received: " + data.length)             });              response.on('end', function(data) {                 console.log('video completed');             });          })         .pipe(res);  });  app.listen(8080); 

but video response works corrupted, instead if request's data written in writeable buffer , saved video file works url. cannot found error or problem in code, here urls :

here url tryed: https://gist.github.com/franciscan/f2bb86f8ff73b45fa192

thanks :)

remove writehead 200, when streaming, should return http 206 results (partial content), , not http200. have same scenario (streaming video file blob container in cloud angular application), there no need http200 response.

update: adding code on how it:

azurestoragehelper.prototype.streamblob = function streamblob(req, res, blob, params) {     if(!params){         params.container = container;     }     blob_service.getblobproperties(params.container, blob, function (error, result, response) {         if(!result) return res.status(404).end();         if(error) return res.status(500).end();          var bloblength = result.contentlength;         var range = req.headers.range ? req.headers.range : "bytes=0-";         var positions = range.replace(/bytes=/, "").split("-");         var start = parseint(positions[0], 10);         var end = positions[1] ? parseint(positions[1], 10) : bloblength - 1;         var chunksize = (end - start) + 1;         var options = {             rangestart: start,             rangeend: end,         }          //this what's interesting scenario. used set myself it's handled azure storage nodejssdk          /*res.writehead(206, {             'accept-ranges': 'bytes',             'content-range': "bytes " + start + "-" + end + "/" + bloblength,             'content-type': result.contenttype,             'content-length': chunksize,             'content-md5': result.contentmd5,         });*/          var options = {             rangestart: start,             rangeend: end,         }  //this api azure storage nodejssdk use. might want check source of method in github see how lib deals http206 responses , piping         blob_service.getblobtostream(params.container, blob, res, options, function (error, result, response) {             if (error) {                 return res.status(500).end();             }         });     }); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -