设置内容处置,使用DOCX回形针回形针、内容、DOCX

2023-09-11 10:02:37 作者:失眠病态男i

荫试图内容处置添加到我的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