Skip to content
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

Wrong Content-Type for Adobe Illustrator and Microsoft Office files #2704

Closed
shunichi opened this issue Sep 12, 2023 · 3 comments
Closed

Wrong Content-Type for Adobe Illustrator and Microsoft Office files #2704

shunichi opened this issue Sep 12, 2023 · 3 comments

Comments

@shunichi
Copy link

shunichi commented Sep 12, 2023

Some uploaded files have wrong content-type with carrierwave 3.0.3.

With carrierwave 3.0.3:

  • Adobe Illustrator files (*.ai) are identified as application/pdf.
  • Some Excel files (*.xlsx) are identified as application/zip. (Some Excel files are identified correctly)

With carrierwave 2.2.4:

  • Adobe Illustrator files (*.ai) are identified as application/illustrator.
  • Excel files (*.xlsx) are identified as application/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

Marcel::Magic.by_magic(io).try(:type)

with:

Marcel::MimeType.for io, name: original_filename, declared_type: declared_content_type

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 and declared_content_type is nil)

@Juju-62q
Copy link

Juju-62q commented Oct 3, 2023

I have similar problem for with *.csv files.

With carrierwave 3.0.3:

  • Comma-Separated Values files (*.csv) are identified as text/plain.

With carrierwave 2.2.4:

  • Comma-Separated Values files (*.csv) are identified as text/csv.

With #2705 branch, *.csv files are now identified as text/csv.

@rajyan
Copy link
Contributor

rajyan commented Oct 28, 2023

@mshibuya
Do you have some time looking into this issue?
This might be a blocking issue for some people upgrading to 3.x.

@mshibuya
Copy link
Member

mshibuya commented Dec 3, 2023

Closed by #2705.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants