0

I am trying to download a video file from a friends server. I manage to download the subtitle file doing this:

var file = fs.createWriteStream('sub.srt');
      var request = https.get(subtitleTrackURL, function(response) {
        response.pipe(file);
      });

But when I try to get the video file using the same method all I get is an empty file:

var file = fs.createWriteStream('video.mp4');
      var request = https.get(videoFileURL, function(response) {
        response.pipe(file);
      });

The video "downloads" instantly (more like not at all since the file is empty) but it is supposed to be about 400MB and should as such take a bit of time.

I am thinking that there must be some encoding or content type that I have to provide for the video file request (the subtitle file is after all just text), but I can't figure out how or what I need to provide. Google was surprisingly unhelpful in how to download a video file using node. So if I should be using something other than https, I am open to suggestions.

Skillzore
  • 748
  • 7
  • 21
  • 1
    You shouldn't assume that your code to create the HTTPS request completes successfully. For debugging purposes it would be helpful if you handle the `.on('error', ...)` event and also print out some debugging of the headers as is shown here -- https://nodejs.org/api/https.html#https_https_get_options_callback – JayReardon Jan 03 '19 at 22:18
  • This might help - https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries – Rastalamm Jan 04 '19 at 04:00

0 Answers0