Paperclip uploads for office files (docx,pptx) are being downloaded as zip files?

Seems like you don't have MIME types registered.

Office files that end in x (Office 2007+) are indeed zipped XML files. Anything that uses normal MIME types will assume it as a zipped file.

MIME types for office 2007+ files

| File |                             MIME type                                   |
+------+-------------------------------------------------------------------------+
|.docx |application/vnd.openxmlformats-officedocument.wordprocessingml.document  |
+------+-------------------------------------------------------------------------+
|.xlsx |application/vnd.openxmlformats-officedocument.spreadsheetml.sheet        |
+------+-------------------------------------------------------------------------+
|.pptx |application/vnd.openxmlformats-officedocument.presentationml.presentation|

In your config/initializers/mime_types.rb file, add the required field, like the example below;

"application/vnd.openxmlformats-officedocument.presentationml.presentation", :pptx

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

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

You may refer paperclip adapters.

You may read Description of the default settings for the MimeMap property and for the ScriptMaps property in IIS , Office 2007 MIME types for Apache , Uploading docx files with Paperclip and Rails and Dynamic Word (.docx) Documents in Rails also.


The 'x' versions of the Office formats ARE zip files - zipped xml. As such, anything that determines file extensions based on mime types will always see them as zip files.


It turns out, as Marc B first hinted at - that all Office documents that end in x are indeed zipped XML files. Anything that uses normal mimetypes will assume that it's a zipped file.

To get around this, you have to register the Office mimetypes with your server. So, for your .pptx files, you put

Mime::Type.register "application/vnd.openxmlformats-officedocument.presentationml.presentation", :pptx

in your config/initializers/mime_types.rb file.

Alternatively, you can use the Rack::Mime::MIME_TYPES.merge!() method, which is seen in action in this Stackoverflow answer, if you have to support all of the Office 2007 files.