Search code examples
cloudinaryrails-activestorageruby-on-rails-6

Rails: Retrieving JPG instead of HEIC from Cloudinary


I'm currently working on a Rails 6 application using ActiveStorage where I'm trying to render images as jpg. I'm using Cloudinary to render the images. I'm trying to support .HEIC images in my web app. A user can upload HEIC images to Cloudinary but I would like for my application to render the image as jpg

When I render the image I see that the browser is rendering the HEIC image which is not supported by browsers. enter image description here

ActiveStorage uploads the image to the cloud:

Redirected to http://res.cloudinary.com/XXXXXXXXX/image/upload/xxxxxxxxxxxq3r4.HEIC
Completed 302 Found in 24ms (ActiveRecord: 16.1ms | Allocations: 2588)
[ActiveJob] [ActiveStorage::AnalyzeJob] [ac0d5880-xxxxxxxxxxxxxxxxxxxxxxxxxx]   Cloudinary Storage (338.6ms) Downloaded file from key: kjpith3bxxxxxxxxxxxxxxxx
[ActiveJob] [ActiveStorage::AnalyzeJob] [ac0d5880-a243-4fef-xxxxxxxxxxxxxxxxxxxx] Skipping image analysis because ImageMagick doesn't support the file

However, I try to render the image from the views as jpg using the following.

<%= cl_image_tag(url_for(post.image), :format => :jpg , class: "card-home__img") %>

But the image is still calling the HEIC image format from this url:

https://res.cloudinary.com/artsyspace/image/upload/v1584732132/wbnknx9ighl6p4ok072u7kd8r5og.heic

Instead of calling the jpg

https://res.cloudinary.com/artsyspace/image/upload/v1584732132/wbnknx9ighl6p4ok072u7kd8r5og.jpg

How can I configure Cloudinary and ActiveStorage to render images or convert images to jpg?


Solution

  • In Rails 6, .key will return the Cloudfare's image ID.

    <%= cl_image_tag(post.image.key, :format => :jpg , class: "card-home__img") %>