-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Wrong Content-Type for Adobe Illustrator and Microsoft Office files #2704
Description
Some uploaded files have wrong content-type with carrierwave 3.0.3.
With carrierwave 3.0.3:
- Adobe Illustrator files (
*.ai) are identified asapplication/pdf. - Some Excel files (
*.xlsx) are identified asapplication/zip. (Some Excel files are identified correctly)
With carrierwave 2.2.4:
- Adobe Illustrator files (
*.ai) are identified asapplication/illustrator. - Excel files (
*.xlsx) are identified asapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet.
I know *.ai is a PDF with specific metadata and *.xlsx is a ZIP.
But *.ai should be downloaded as Adobe Illustrator file.
I think this commit cause the issue.
a2ca59c
It may be fixed if replcacing this line
carrierwave/lib/carrierwave/sanitized_file.rb
Line 324 in 8815592
| Marcel::Magic.by_magic(io).try(:type) |
with:
Marcel::MimeType.for io, name: original_filename, declared_type: declared_content_typeActiveStorage identifies files in the same way.
https://github.com/rails/rails/blob/b5d63b9b16c6f251eaa08f61086f21ff3ef3292f/activestorage/app/models/active_storage/blob.rb#L353-L355
But I don't know it is a correct way to fix the issue.
It slightly changes the behavior in guessed_safe_content_type case. (in a case where Marcel can't detect the type from the file content and declared_content_type is nil)