I’m working on a download service which grants users a one-time-download
access to files. The idea is to write an entry to a database table after
a successful download that “locks” the download link for the user.
After doing some quick tests with send_file I noticed that send_file
does not block until the user has downloaded the full file, but proceeds
with the rest of the controller code. For example:
send_file fullpath, :stream => false, :disposition => ‘attachment’,
:filename => filename
logger.info “*********** LOCK DOWNLOAD!! **************”
After send_file starts the file transfer, I can immediately see the
“LOCK DOWNLOAD” entry in the log files. This would mean that if the user
interrupts a big file download, it would still be locked.
What would be the solution? Do I have to somehow (…how?) write my own
buffering file sending which blocks the control and breaks out of the
controller if the user interrupts the transfer?
I would imagine :stream => true could be a step closer to my needs, but
it doesn’t seem to work since all I get is “Rails application failed to