2011-01-30 36 views
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)具有完美的內容。

問候,

回答

0

嘗試發送一個簡單的文件,看看它是否工作

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

this thread,我認爲它有你需要的一切。

+0

事實證明,我必須在發送之前「刷新」由P​​DFTK創建的文件。對不起,沒有提到問題中的更多細節。 – Dominic 2011-02-10 15:27:44

相關問題