1
我想發送一個pdf回給用戶,但我有嚴重的問題讓send_file和send_data工作。我創建的pdf文件如下:rails send_file和send_data發送零字節文件
tmp = Tempfile.new('filled')
new_tmp_path = PDFPrint.fill_form_using_pdftk(template_path, tmp.path)
send_file (new_tmp_path, :filename => 'filled.pdf')
瀏覽器提示下載,但下載的fill.pdf文件有零字節。 我已驗證new_tmp_path確實包含一個有效的PDF
我曾經嘗試這樣做(好,填充內容):
File.open(new_tmp_path, 'r') do |f|
send_data(f.read, :filename => "filled.pdf")
end
但是,這也給了我同樣的下載 - >零字節問題,而服務器上的文件(new_tmp_path)具有完美的內容。
問候,
事實證明,我必須在發送之前「刷新」由PDFTK創建的文件。對不起,沒有提到問題中的更多細節。 – Dominic 2011-02-10 15:27:44