Man*_*ran 3 ruby-on-rails amazon-s3 paperclip
我试图Content-Disposition在s3中添加到我的docx文件.有点像:Content-Disposition: attachment; filename="filename.docx".我想这样做是因为IE(<9)将docx文件作为zip文件下载.经过一些谷歌搜索,我发现有一个解决方法,通过添加content-disposition内容也是如此.我尝试使用 before_post_process回电并做了
before_post_process :set_content_disposition
def set_content_disposition
filename = self.attachment.instance.attachment_file_name
self.attachment.instance_write(:content_disposition, "attachment; filename="+filename)
end
Run Code Online (Sandbox Code Playgroud)
但是,它仍然以zip文件的形式下载.有没有办法正确地做到这一点.
Prozac的答案(使用before_post_process编辑选项)对我不起作用.但是,无论如何,现在有一种更简单的方法.您可以将proc直接传递给has_attached_file调用的options散列中的:s3_headers键:
has_attached_file :attachment, {
...,
:s3_headers => lambda { |attachment|
# pass whatever you want in place of "attachment.name"
{ "Content-Disposition" => "attachment; filename=\"#{attachment.name}\"" }
},
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3178 次 |
| 最近记录: |