更新时间:2023-11-24 12:20:58
我使用 send_data 而不是 send_file,然后我删除了文件.send_data 将阻塞直到数据发送,允许 File.delete 请求成功.
I use send_data instead of send_file, then I delete the file. send_data will block until the data is sent, allowing File.delete request to succeed.
file = temp.path
File.open(file, 'r') do |f|
send_data f.read.force_encoding('BINARY'), :filename => filename, :type => "application/pdf", :disposition => "attachment"
end
File.delete(file)