开发者

rails send_file and send_data sends out zero byte files

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,


Try sending a simple file to see if it works

send_file '/path/to.jpeg', :type => 'image/jpeg', :disposition => 'inline'

Read this thread, I think it has everything you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜