0

I have extracted direct link to youtube file and need to start download once a link is clicked. I use HTML5 download="filename", but it doesn't work in IE or Opera. I've seen solutions with adding to file Header in PHP, but how could it be done using Meteor.js or Node.js.

EDIT: Solution for Node.js , but still wondering about Meteor.js

<a href="http://example.com/file.mp4" download="filename">Link</a>
Community
  • 1
  • 1
mhlavacka
  • 691
  • 11
  • 25

1 Answers1

0

Consider using iron:router

On server you do:

var fs = Npm.require('fs');

Router.route('/files/:fileName', function() {

  var file = this.params.fileName;

  // Attempt to read the file size
  var stat = null;
  try {
    stat = fs.statSync(file);
  } catch (_error) {
    console.log(this.response);
  }

  // Set the headers
  this.response.writeHead(200, {
    'Content-Type': 'application/zip',
    'Content-Disposition': 'attachment; filename=' + file
    'Content-Length': stat.size
  });

  // Pipe the file contents to the response
  fs.createReadStream(file).pipe(this.response);
},
{where: 'server'});
Community
  • 1
  • 1
ZuzEL
  • 12,768
  • 8
  • 47
  • 68
  • Thanks for answering, but I'm still a bit lost bc I haven't used iron:router that much. The file I need to download is not actually a file like video.mp4, but direct link to that file - https://goo.gl/Z19ShH on youtube. So after I extract this link in server method, should I call Router.go with the link as a parameter? – mhlavacka Jul 14 '15 at 17:43