I'm trying grab the following PDF file from a node.js server running on Heroku. https://limitless-depths-2785.herokuapp.com/file/geo3a.pdf
If I go to that url within my browser, the PDF loads. What I would like to do is make an AJAX or GET call to that URL using jQuery or JavaScript and save it to the phone. I'm not sure exactly what I need to do on the server to configure it to send the pdf in a way that it can be saved to the phone or what call to make on the client side to receive that PDF file properly.
Here is my client side code.
$('#myButtonPdf').on('click', function () {
alert("Loading Pdf");
$.get( "https://limitless-depths-2785.herokuapp.com/file/geo3a.pdf", function( data ) {
$( ".result" ).html( data );
alert( "Loaded PDF" );
});
});
Here is my Node.js server side code to serve up static files.
app.get('/file/:name', function (req, res, next) {
var options = {
root: __dirname + '/public/',
dotfiles: 'deny',
headers: {
'x-timestamp': Date.now(),
'x-sent': true
}
};
var fileName = req.params.name;
res.sendFile(fileName, options, function (err) {
if (err) {
console.log(err);
res.status(err.status).end();
}
else {
console.log('Sent:', fileName);
}
});
});