John
John

Reputation: 4706

send_file return value

Does the send_file method in Rails give a return value? I'd like to do one thing if the sending is successful, and another thing if the sending is not successful. I looked at the documentation at this link, but did not find anything relevant.

Upvotes: 2

Views: 882

Answers (1)

mccannf
mccannf

Reputation: 16659

No, there is no way to confirm download completion or success with send_file. From this question: Can we find out when a Paperclip download is complete? :

send_file creates the file and then passes a special header to tell the webserver telling it what to send. Rails doesn't actually send the file at all, it sets this header which tells the webserver to send the file but then returns immediately, and moves on to serve another request. To be able to track if the download completes you'd have to occupy your Rails application process sending the file and block until the user downloads it, instead of leaving that to the webserver (which is what its designed to do). This is super inefficient.

You may be able to do something using cookies and JavaScript on the client. See this question: Rails File Download And View Update - Howto?

Upvotes: 2

Related Questions