Closed shunichi closed 7 months ago
I have similar problem for with *.csv
files.
With carrierwave 3.0.3:
*.csv
) are identified as text/plain
.With carrierwave 2.2.4:
*.csv
) are identified as text/csv
.With https://github.com/carrierwaveuploader/carrierwave/pull/2705 branch, *.csv
files are now identified as text/csv
.
@mshibuya Do you have some time looking into this issue? This might be a blocking issue for some people upgrading to 3.x.
Closed by #2705.
Some uploaded files have wrong content-type with carrierwave 3.0.3.
With carrierwave 3.0.3:
*.ai
) are identified asapplication/pdf
.*.xlsx
) are identified asapplication/zip
. (Some Excel files are identified correctly)With carrierwave 2.2.4:
*.ai
) are identified asapplication/illustrator
.*.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. https://github.com/carrierwaveuploader/carrierwave/commit/a2ca59cbe67046ba7818c64849a9a4ffa90306db
It may be fixed if replcacing this line https://github.com/carrierwaveuploader/carrierwave/blob/8815592942f6c768d432dc6398a441f0c4f6118b/lib/carrierwave/sanitized_file.rb#L324 with:
ActiveStorage 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 anddeclared_content_type
is nil)