加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用paperclip设置docx的内容处理

发布时间:2020-12-17 01:45:54 所属栏目:百科 来源:网络整理
导读:我试图在s3中添加Content-Disposition到我的docx文件.类似的内容:内容 – 处置:附件;文件名= “filename.docx”.我想这样做是因为IE( 9)将docx文件作为zip文件下载.经过一些谷歌搜索后,我发现有一个解决方法,通过添加内容处理内容也是如此.我尝试使用befor
我试图在s3中添加Content-Disposition到我的docx文件.类似的内容:内容 – 处置:附件;文件名= “filename.docx”.我想这样做是因为IE(< 9)将docx文件作为zip文件下载.经过一些谷歌搜索后,我发现有一个解决方法,通过添加内容处理内容也是如此.我尝试使用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

但是,它仍然以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}"" }
  },...
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读