Ask A Question

Notifications

You’re not receiving notifications from this thread.

Notify users PDF creation is ready and can be downloaded

John van Arkelen asked in Rails
Users can create a PDF in my app which takes some time to generate, so it has to be done in a background job. No problem, but then there is a delay and the user must be notified that the PDF is ready.

So the first choice to make is to either send them an email with a download link or a push notification in the app itself. My preference is the push notification, so I guess ActionCable is the way to go? My app runs on Heroku, so is ActionCable also a good choice then or is another solution preferable?

Then there is another consideration, where to store the generated PDF until the user downloads it? I could upload it to Azure/S3/etc with ActiveStorage, or I could store it temporarily in an app folder and delete it after download. My preference is to do the last, because the PDF is there only for a few minutes and therefore the hassle to store it in the cloud is not really needed?
Reply
You could send them the message with ActionCable right after your PDF code finishes generating the file. You'd have to store the file somewhere and then include the link to it. Probably S3 for storage. 

The problem with deleting the file after the user downloads it is that you then break the link. If they click the link again they'll get a 404 and you'll certainly end up with support calls dealing with that.

With email, you could generate the PDF and just email it over as an attachment. That way you wouldn't have to store a copy of the file and the user can always reference the file as long as they don't delete the email. This would probably be easiest to manage overall if you don't want to store the PDFs permanently on S3.
Reply

Hi Chris,

Attaching the PDF in the email is a great idea, thanks!
Then there is no need for both ActionCable and ActiveStorage, just a message that the email with PDF will be delivered later.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.