Paperclip uploads for docx file is being downloaded as zip files?

I have checked the Mimetype of the docx file and it shows: 'application/octet-stream'

But checking it without any content in it shows application/vnd.openxmlformats-officedocument.wordprocessingml.document as mimetype.

I don't know whether the problem is with the content inside the file also, while uploading the file with paperclip it shows:

@content_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document", @headers="Content-Disposition: form-data;

But when we check the file content after the upload it shows as "application/zip".

Tried all the mimetypes, but it doesn't seams to work.

Meanwhile other docx files are uploaded and downloaded in fine way, this particular file alone been downloaded as zip file while downloading it form s3 bucket.

I cannot provide the file because it is confidential so please leave suggestions if you have any solution for this ?

Note: the same file when it is uploaded in google drive and downloaded or also downloaded in safari it is downloaded fine the problem occurs when downloading it in chrome browser.

1 answer

  • answered 2020-07-11 18:58 Farah Assaf

    Try adding this to your config/initializers/mime_types.rb

    [['application/vnd.openxmlformats-officedocument.presentationml.presentation', [[0..2000, 'ppt/']]],
     ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', [[0..2000, 'xl/']]],
     ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', [[0..2000, 'word/']]]].each do |magic|
      MimeMagic.add(magic[0], magic: magic[1])
    end
    Don't forget to restart the server after :)