The problem lies in the following code ("routes.rb").
post 'download_csr' do
file_name = File.dirname(__FILE__) + '/cert.csr'
File.open(file_name, 'w') do |f|
f.write params[:csr]
end
send_file file_name, :disposition => 'attachment'
erb :load_certificate, :locals => { :csr => 'cert.csr' }
end
The flow is this: the user clicks a button on a form, then a file is written and downloaded to local system, then it goes to another page (ie, "load_certificate.erb").
However, what really happens is that after the file is downloaded, it doesn't go to the next page. But if I comment out "send_file", it will go to the next page. So how to address this? Thanks a lot!
One more thing: it would be good to make sure the file is actually downloaded before going to the next page (because when send_file pops out a window, the user can choose "cancel"). Some time-out mechanism may not work here.
@Soup's link is a good one to read. With regard to Sinatra, send_file
calls halt
, which ends the request (in this case by sending the status and the file). Nothing will be processed after a halt
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.