Grab PDF from Server Side Route and Attach to an email

I have a server side route that generates a pdf, let’s call it ‘/server/pdf’. This route serves the pdf as a ‘Content-Type’: application/pdf, and delivers it inline (‘Content-Disposition’: inline), meaning the file is displayed in the browser instead of being downloaded.

I want to attach this pdf to an email. Is there a way I can grab the pdf file from the browser or from the server without having to save the file in permanent storage (i.e., upload to Amazon S3)? I want something to the effect of:

on the client:

Template.sendEmail.events({
  'click #send-button': function(event) {
    event.preventDefault();

    // some code to grab pdf file from url '/server/pdf'
    var file = download.file('/server/pdf');

    Meteor.call('sendEmail', file, function(error, result) {
      // handle error
    });
  }
});

OR, on the server:

Meteor.methods({
  'sendEmail': function() {
    // some code to grab pdf file from url '/server/pdf'
    var file = download.file('/server/pdf');

    Email.send(...);
  }
});

There was some discussion about something similar a while back; this might help.

1 Like