开发者

Rails with paperclip Docx content_type is coming back as application/zip

Has an开发者_如何学Goyone else seen this?

I'm using rails 3 with paperclip, when I upload a .doc it works great application/msword but when I upload a .docx the content_type is being saved as application/zip.

thoughts?


Ironically IE can have difficulty recognising the new MS Office files while other browsers recognise them fine.

In order to get IE working with these files you need to add the mime types to the server config. In Rails this is done in 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

If your app is proxied through Apache and Apache serves your static assets you'll also have to configure apache with the new mime types (and restart) as per http://bignosebird.com/apache/a1.shtml

My mime types were located at /etc/mime.types but try locate mime.types if you're not sure.


I've seen this using IE with SSL. If that's the case for you, take a look at http://www.kalzumeus.com/2010/10/25/how-to-use-ssl-to-secure-your-rails-app-against-firesheep-and-other-evils/

(The section called "Host downloadable files on SSL? You just broke IE.")

this may also help: Rails PDF Generation with Prawn in IE7

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜