Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download pdf asynchronously

When a user clicks on a links in my Ruby on Rails app, a PDF file is generated in background.

The app is polling the server to know when the PDF file is ready, and then it should ask the user to download it as if he clicked on a PDF link that already existed.

We do this with an hidden iframe and change the src attribute when the PDF file is ready.

While it works on Firefox (there's a native pop up for downloading the file), it does not on safari/chrome. How should I do this? I've seen there's a Content-Disposition HTTP header, but the PDF file is stored on S3, so I don't think I can use that method.

like image 765
ksol Avatar asked May 14 '12 09:05

ksol


1 Answers

You do need to use the Content-Disposition = 'attachment'; response header.

I'm not totally up to the play with S3 so let me know if this answer isn't quite right but it seems you are able to set the content headers in the request URL now, see example here.

like image 57
Louis Avatar answered Oct 09 '22 10:10

Louis