Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Has anyone 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?

like image 435
AnApprentice Avatar asked Jan 27 '11 00:01

AnApprentice


2 Answers

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.

like image 95
Paul Odeon Avatar answered Sep 17 '22 23:09

Paul Odeon


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

like image 25
njorden Avatar answered Sep 21 '22 23:09

njorden