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

Mime types bug in refinerycms-images and/or refinerycms-dragonfly? #3532

Open
evenreven opened this issue Oct 22, 2023 · 1 comment
Open

Comments

@evenreven
Copy link
Contributor

evenreven commented Oct 22, 2023

Context: it seems image/webp is not part of the standard hash of extensions to mime types in Dragonfly, and browsers read the content type as "octet-stream". Dragonfly.app.mime_types in the Rails console returns everything under the sun except image/webp. So whitelisting it in the refinery initializers doesn't work because Dragonfly won't find it to begin with (change the extension to almost anything else, and it will work).

I assume it's this issue that the array of additional mime type in the initializer (config/initializers/refinery/dragonfly.rb) is meant to solve?

But I can't find a way to register mime types that will actually be picked up by refinerycms-images. I've tried putting a Dragonfly compatible hash inside the refinery dragonfly initializers, and although it seems like it's picked up by the Refinery::Dragonfly module, it still doesn't work.

This is what I'm trying to do:

diff --git a/config/initializers/refinery/dragonfly.rb b/config/initializers/refinery/dragonfly.rb
index 0920e0ce..daec5121 100644
--- a/config/initializers/refinery/dragonfly.rb
+++ b/config/initializers/refinery/dragonfly.rb
@@ -21,7 +21,7 @@ Refinery::Dragonfly.configure do |config|
   # config.fetch_file_whitelist = nil
   # config.fetch_url_whitelist  = nil
   # config.generators           = []
-  # config.mime_types           = []
+  config.mime_types           =  [".webp" => "image/webp"]
   # config.name                 = "dragonfly"
   # config.path_prefix          = nil
   # config.plugin               = "libvips"
diff --git a/config/initializers/refinery/images.rb b/config/initializers/refinery/images.rb
index 241d56da..438fa266 100644
--- a/config/initializers/refinery/images.rb
+++ b/config/initializers/refinery/images.rb
@@ -18,7 +18,7 @@ Refinery::Images.configure do |config|
   # config.user_image_sizes = {:small=>"110x110>", :medium=>"225x255>", :large=>"450x450>"}
 
   # Configure white-listed mime types for validation
-  # config.whitelisted_mime_types = ["image/jpeg", "image/png", "image/gif", "image/tiff"]
+  config.whitelisted_mime_types = ["image/jpeg", "image/webp" "image/png", "image/gif", "image/tiff"]
 
   # Configure image view options
   # config.image_views = [:grid, :list]

Is this a bug, or am I holding it wrong?

@evenreven
Copy link
Contributor Author

To rule out upstream issues, I tried using Dragonfly on a barebones Rails 7 app without Refinery now, and although it doesn't work out of the box (it says octet-stream), it's as easy as adding mime_type "webp", "image/webp" in the configure block of config/initializers/dragonfly.rb as suggested here.

It's not an apples to apples comparison (because it's a Rails 7 app), but still it makes me believe Dragonfly just doesn't see the mime_type Refinery tries to add.

Any help/pointers would be very welcome!

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

1 participant