New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CarrierWave sets wrong content type on XLSX files #1995
Comments
@resistorsoftware here's an extremely terrible hack I'm using in the meantime:
|
If I'm following everything correctly... The documentation here states:
The mime-types gem appears to be: https://github.com/mime-types/ruby-mime-types And it's seems these sorts of files are not accommodated. I could not find XLSX or similar files in the supported types, so I believe this to be an issue in that upstream dependency. |
I became hopeful when I read the Contributing documentation:
The latest versions of mime-types-data appear to support XLSX and others, so I'm not sure what's happening here. |
I forked one of @mehlah's content-type test scripts, hacked in a quick content-type check on an XLSX doc, and it correctly detected |
@resistorsoftware: In my case, I've determined that there's a disconnect between the content-type sent by our front-end and that actually delivered to Carrierwave. It's definitely an issue somewhere within our own code. I suggest getting a handle on all the code layers in your control between upload in the browser and the Carrierwave library and verifying the content-type perceived in each. |
The resolution to my issue ended up looking like this: def attachment
#Added this line to resolve what turned out to be an attribute mapping issue:
file[:content_type] = file[:type]
@attachment ||= Attachment.new(file: file)
end Hope this helps. |
Thanks so much for the explanations. I validated using Pry that the gem should've been able to detect the proper content type using the extension as is, which troubled me. Why was the content type mangled? So at that point I made a hack on the result, and used a really dumb update on the S3 file to force its content type to be correct. I will follow through this thread and see if I can get CarrierWave to work thus eliminating the crazy S3 hack! Thanks again! |
The same problems for me |
Mimemagic comes with extra magic you can overlay on top of the defaults to correctly detect these file types. Enable it like this:
|
#1934 has made MimeMagic as default way to detect MIME types, so this should be no longer an issue. |
I recently upgraded from 1.3.1 to the latest 2.1.0 and I am now experiencing this same problem with XLSX and DOCX files. The uploader detects things properly, but after saving the file the content_type is |
We experienced the same issue and fix as @andyrue on a Rails 5.2 app. |
It looks like this may have been fixed again in #2447 which was included in the 2.2.0 release 🎉 |
We are running into a similar problem with |
Currently using this temporary workaround for setting the content type of the file manually: class SomeUploader < CarrierWave::Uploader::Base
process :apk_content_type
def apk_content_type
if current_path.end_with?('.apk')
file.content_type = 'application/vnd.android.package-archive'
end
end |
My incoming upload has the right content type. A before store action shows the right content type. But the actual stored file on S3 has the wrong content type!! How to correct that?
The text was updated successfully, but these errors were encountered: