设置内容处置,使用DOCX回形针 [英] setting content-disposition for docx using paperclip

查看:160
本文介绍了设置内容处置,使用DOCX回形针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

荫试图内容处置添加到我的docx文件S3。 内容处置:沿东西线连接;文件名=filename.docx。我想这样做,是因为IE浏览器(小于9)下载的docx文件的zip文件。一些谷歌上搜索后,我发现有一种解决方法,通过增加一个内容处置的内容为好。我试着用 before_post_process 回电,做

Iam trying to add Content-Disposition to my docx files in s3. Something along the lines of: Content-Disposition: attachment; filename="filename.docx". I want to do this because IE (< 9) downloads docx files as zip files. After some googling I found that there is a workaround for this, by adding a content-disposition to the content as well. I tried using the before_post_process call back and did

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

但是,它仍然是下载zip文件。有没有办法正确地做到这一点。

But, it still downloads as zip file. Is there a way to correctly do this.

推荐答案

我终于找到了一种方法..有一个 before_post_process 回调回形针宝石。

I finally found a way .. there is a before_post_process callback with paperclip gem.

我们可以做这样的事情。

we can do something like this..

has_attached_file :sample
before_post_process :set_content_dispositon

def set_content_dispositon
  self.sample.options.merge({:s3_headers => {"Content-Disposition" => "attachment; filename="+self.sample_file_name}})
end

这篇关于设置内容处置,使用DOCX回形针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆