带回形针的Rails Docx content_type将作为应用程序/ zip返回

时间:2011-01-27 00:33:24

标签: ruby-on-rails ruby-on-rails-3 paperclip mime mime-types

有没有人见过这个?

我正在使用带有回形针的rails 3,当我上传一个.doc时,它可以很好地应用/ msword但是当我上传一个.docx时,content_type被保存为application / zip。

想法?

2 个答案:

答案 0 :(得分:5)

具有讽刺意味的是,IE可能难以识别新的MS Office文件,而其他浏览器则认为它们很好。

为了让IE使用这些文件,您需要将mime类型添加到服务器配置中。在Rails中,这是在config / initializers / mime_types.rb

中完成的
Mime::Type.register "application/vnd.openxmlformats-officedocument.wordprocessingml.document", :docx
Mime::Type.register "application/vnd.openxmlformats-officedocument.presentationml.presentation", :pptx
Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx

如果您的应用程序是通过Apache代理的,并且Apache为您的静态资产提供服务,您还必须根据http://bignosebird.com/apache/a1.shtml

为新的mime类型配置apache(并重新启动)

我的mime类型位于/etc/mime.types,但如果您不确定,请尝试locate mime.types

答案 1 :(得分:1)

我已经在IE中使用SSL看到了这一点。如果是这种情况,请看一下 http://www.kalzumeus.com/2010/10/25/how-to-use-ssl-to-secure-your-rails-app-against-firesheep-and-other-evils/

(“SSL上的主机可下载文件?您刚刚破坏了IE”这一节。)

这也可能有所帮助: Rails PDF Generation with Prawn in IE7