Rails send_file 和 send_data 发送零字节文件
我正在尝试将 pdf 发送回用户,但在使 send_file 和 send_data 正常工作时遇到严重问题。我创建的pdf文件如下:
tmp = Tempfile.new('filled')
new_tmp_path = PDFPrint.fill_form_using_pdftk(template_path, tmp.path)
send_file (new_tmp_path, :filename => 'filled.pdf')
浏览器提示下载,但下载的filled.pdf文件有零字节。 我已经验证 new_tmp_path 确实包含有效的 pdf (良好的、填充的内容)
我已经尝试过:
File.open(new_tmp_path, 'r') do |f|
send_data(f.read, :filename => "filled.pdf")
end
但这也给我带来了相同的下载->零字节问题,而服务器上的文件(new_tmp_path)具有完美的内容。
问候,
I'm trying to send a pdf back to the user but I'm having serious problem getting send_file and send_data to work. I created the pdf file as follows:
tmp = Tempfile.new('filled')
new_tmp_path = PDFPrint.fill_form_using_pdftk(template_path, tmp.path)
send_file (new_tmp_path, :filename => 'filled.pdf')
The browser prompts for a download, but the downloaded filled.pdf file has zero byte.
I have verified that new_tmp_path does contain a valid pdf (good, filled content)
I have tried this:
File.open(new_tmp_path, 'r') do |f|
send_data(f.read, :filename => "filled.pdf")
end
But this also gives me the same download->zero-byte problem, while the file on server (new_tmp_path) has perfect content.
Regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试发送一个简单的文件,看看它是否有效
阅读此线程,我想它有你需要的一切。
Try sending a simple file to see if it works
Read this thread, I think it has everything you need.