1

我有一个 Rails 应用程序,它创建了几个 csv 文件,将它们压缩并使用以下行将它们作为附件(供下载)发送到客户端:

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

当我查看在服务器上创建的压缩文件时,我可以使用它,但是,当我通过应用程序下载文件时,它会解压缩成一个.zip.cpgz文件,而反过来又压缩成一个zip压缩成文件的.zip.cpgz文件等, ETC。

然后我下载了“The Unarchiver”应用程序(在 Mac OSX 上),当我尝试打开.zip文件时出现错误:"the contents cannot be extracted with this program"

有谁知道为什么会这样?编码错误等?上面的行或我的配置中是否缺少可以解决此问题的内容?

4

2 回答 2

0

您尝试流式传输 ZIP 文件。尝试添加:disposition => 'attachment'以强制浏览器下载完整文件。

于 2012-02-06T15:19:12.870 回答
0

尝试使用类似这样的设置 Content-Disposition 响应标头

response.headers['Content-Disposition'] = "attachment; filename=\"#{@filename}\""
于 2015-02-12T06:28:02.000 回答