2012-02-06 109 views
1

我有一個創建幾個CSV文件,拉鍊起來,並用這條線將它們發送到客戶端作爲附件(下載)Rails應用程序:發送壓縮文件作爲附件

send_file t.path, :x_sendfile => true, :type => 'application/zip', :filename => "invited_friends_stats.zip" 

當我查看服務器上創建的壓縮文件,但我可以使用它,但是,當我通過應用程序下載文件時,它將解壓縮爲.zip.cpgz文件,然後壓縮爲zip文件,壓縮爲.zip.cpgz文件,等等等等。

然後我下載了「The Unarchiver」應用程序(在Mac OSX上)和whe ñ我嘗試打開.zip文件我收到一個錯誤:"the contents cannot be extracted with this program"

有沒有人知道爲什麼會發生這種情況?編碼錯誤等?有沒有我從上面的行中缺少的東西,或者在我的配置中會解決這個問題?

回答

0

您嘗試流式傳輸ZIP文件。嘗試添加:disposition => 'attachment'以強制瀏覽器下載完整文件。

0

嘗試這樣

response.headers['Content-Disposition'] = "attachment; filename=\"#{@filename}\"" 
的東西設置內容處置響應頭