Tarlen
Tarlen

Reputation: 3797

Force download from S3 on click

I have files stored on S3, and I want to automatically download them for a user when they click a button

What I've done so far is to have a route

/lib/routes/download

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

Router.route("download", function() {
  console.log('retrieving ' + this.params.signedURL);
  this.response.writeHead(200, {'Content-type': 'appplication/pdf'}, this.params.signedURL);
  this.response.end(fs.readFileSync(this.params.signedURL));
}, { where: 'server', path: '/d/:signedURL'});

But this doesn't work, because i Cant use fs on the client. And even if I could, im not sure this would work

Any advice on how best to accomplish this?

Upvotes: 2

Views: 279

Answers (2)

looshi
looshi

Reputation: 1236

I retrieve the signedUrl via a meteor method call, then do this when the user clicks a download button :

window.open(_signedURL,"_self");

Upvotes: 1

Michel Floyd
Michel Floyd

Reputation: 20256

Easiest way to do this is to use the cfs:s3 package which is an add-on to CollectionFS. This not only supports S3 but also transparently breaks files up into smaller chunks during upload and download to/from S3.

Upvotes: 1

Related Questions