Question

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,

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top