gpt4 book ai didi

ruby-on-rails - 使用回形针设置 docx 的内容处理

转载 作者:行者123 更新时间:2023-12-04 03:40:14 25 4
gpt4 key购买 nike

我正在尝试添加 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

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

最佳答案

百忧解的回答(使用 before_post_process 来编辑选项)对我不起作用。但是,无论如何,现在有一种更简单的方法。您可以将 proc 直接传递给 has_attached_file 调用的选项哈希中的 :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}\"" }
},
...
}

关于ruby-on-rails - 使用回形针设置 docx 的内容处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8396380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com