kreeti / kt-paperclip

Easy file attachment management for ActiveRecord
Other
275 stars 95 forks source link

Improve content type detector #74

Closed ngan closed 2 years ago

ngan commented 2 years ago

Improve content type detector by getting all types back from Marcel and cross-referencing them with the possible types (file extension). This is an improvement because we don't want to trust Marcel to order their magic detection appropriately.

For example, I have a PDF that contains the string wmv2 and Marcel is reporting that it's a video/x-ms-wmv file: https://github.com/rails/marcel/blob/main/lib/marcel/tables.rb#L2164. This is obviously wrong. If we were to use Marcel::Magic.all_by_magic then application/pdf is among the list of types returned. If Marcel considers it to be a possible PDF and the extension declares it as a pdf, let's just go with that.

ssinghi commented 2 years ago

Hi @ngan @sbhawsingka what do you think of https://github.com/kreeti/kt-paperclip/pull/75 I think it will be better to delegate to Marcel for file content type detection completely.

ssinghi commented 2 years ago

Closing in favor of #75