Skip to content

Update image? check for file upload field types#3398

Merged
mshibuya merged 3 commits into
railsadminteam:masterfrom
codealchemy:mime-type-update
Oct 2, 2021
Merged

Update image? check for file upload field types#3398
mshibuya merged 3 commits into
railsadminteam:masterfrom
codealchemy:mime-type-update

Conversation

@codealchemy

Copy link
Copy Markdown
Contributor

Lookup the type via the extension, and match against 'image' types.

Rails provides a way to register custom mime types, allowing additional 'image' types to be added to an Rails application without needing to maintain a list of specific filename extensions in rails_admin

ex. webp

# config/initializers/mime_types.rb
Mime::Type.register 'image/webp', :webp

Related update in Rails adding webp as a valid content type for ActiveStorage rails/rails@2a0823e

Closes #3239

[Lookup the type ](https://apidock.com/rails/v6.0.0/Mime/Type/lookup_by_extension/class)via the [extension](https://apidock.com/rails/ActiveStorage/Filename/extension_without_delimiter), and match against 'image' types.

Rails provides a way to register custom mime types, allowing additional 'image' types to [be added to an Rails application](https://guides.rubyonrails.org/action_controller_overview.html#restful-downloads) without needing to maintain a list of specific filename extensions in `rails_admin`
@codealchemy codealchemy changed the title Update image? check for ActiveStorage fields Update image? check for file upload field types Sep 22, 2021
@mshibuya

Copy link
Copy Markdown
Member

Could add some tests, like webp is considered as an image?

`webp` is not currently a default configured image Mime::Type in Rails, so this includes a check where the application can register a type and RailsAdmin will render it accordingly.

This updates existing coverage as well to test against common image file types.
@mshibuya mshibuya merged commit 10d9c9d into railsadminteam:master Oct 2, 2021
@mshibuya

mshibuya commented Oct 2, 2021

Copy link
Copy Markdown
Member

Great, thanks!

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

Successfully merging this pull request may close these issues.

webp support for image?

2 participants