Uploading docx files with Paperclip and Rails

I just ran into an issue with the Paperclip gem not allowing a user to upload documents of the docx variety even though I had the ‘application/msword’ content type allowed in my model.  It turns out that the docx content type is a much longer string.  To get the upload to validate properly, you need to add the following to your model:

validates_attachment_content_type :attachment, :content_type => [ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']

Once in the model, we had no problem uploading .docx files.

To upload both .doc and .docx files, it turns into:

validates_attachment_content_type :attachment, :content_type => [ 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ]


    beto |

    Thanks! That reduce my headache!

    Magesh |

    Thanks for sharing it :)

    Drew |

    Hi, I used the following to allow the upload of images && all document based content types:

    @@doc_types = {
    :image => ['image/jpg','image/jpeg','image/pjpeg','image/png','image/x-png','image/gif'],
    :pdf => ['application/pdf'],
    :word => ['application/msword','applicationvnd.ms-word','applicaiton/vnd.openxmlformats-officedocument.wordprocessingm1.document'],
    :excel => ['application/msexcel','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
    :powerpoint => ['application/mspowerpoint','application/vnd.ms-powerpoint','application/vnd.openxmlformats-officedocument.presentationml.presentation'],
    :text => ['text/plain']