1

I have a signed Amazon S3 URL which points to a PDF file in a bucket

I want to download this file, not redirect/display it when a button is clicked.

I had figured something like this

Router.route('download', {
  path: '/d/:signedURL',
  onAfterAction: function() {
    var req = this.request;
    var res = this.response;

    res.setHeader('Content-disposition', 'attachment; filename=' + this.params.signedURL);

    console.log(req, res);


  }
}, {where: 'server'});

But can't get it to work, any advice?

EDIT:

Request URL:chrome-extension://invalid/
Request Headers
Provisional headers are shown
Referer:http://localhost:3000/d/https%3A/s3.amazonaws.com/tabler-development/08867c4b0guX7REeBvLHdLaMM%253D
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
X-DevTools-Request-Initiator:frontend
Krzysztof Raciniewski
  • 4,735
  • 3
  • 21
  • 42
Tarlen
  • 3,657
  • 8
  • 30
  • 54
  • The `filename` in this case is the **name** of the file that the user will download as. It isn't a URL. See [this example](https://stackoverflow.com/questions/21565991/how-to-serve-a-file-using-iron-router-or-meteor-itself). I *think* the only way to do this is to actually pre-download the file with the signed URL and then serve it back to the user. I can show this as an answer if you think that's an acceptable solution. – David Weldon Mar 01 '15 at 17:39
  • will that have any significant performance hit on the servers? And please do, that would be much appreciated – Tarlen Mar 01 '15 at 18:18

1 Answers1

0

Try defining your server route as an HTTP GET restful route, and I think you lack a res.end() to acknowledge the response ce be sent to the client.

Router.route("/d/:signedURL",{
  name:"download",
  where:"server"
}).get(function(){
  var req = this.request;
  var res = this.response;
  res.setHeader('Content-disposition', 'attachment; filename=' + this.params.signedURL);
  res.end();
});
saimeunt
  • 22,666
  • 2
  • 56
  • 61