1

I have Item object that #has_many_attached :photos. My Active storage service is GCS. I created a #thumbnail() instance method for Item. Like this:

def thumbnail(photo)
    photo.variant(resize_and_pad: [400, 400, gravity: 'center', background: '#3D4453'])
end 

I called it in the items show.html.erb file as:

 <% @item.photos.each do |photo| %>
    <%= image_tag(@item.thumbnail(photo)) %>
<% end %>

However this caused resized photos to be uploaded in GCS Bucket. So I end up with normal size photos and resized photos in my bucket. How can I avoid this ?

1 Answers1

1

According to the ActiveStorage documentation for variants, it is intended behavior that the variants are uploaded to the storage service you are using (in this case GCS), which then returns the variant URL for use in your application:

This will check that the variant has already been processed and uploaded to the service, and, if so, just return that. Otherwise it will perform the transformations, upload the variant to the service, and return itself again.

This related thread explores this behavior of having a variant and the original file, and it comes down to building functionality to remove the variant files, since the API doesn’t seem to support it. For deleting specific variant files, this other question addresses this issue.

ErnestoC
  • 2,660
  • 1
  • 6
  • 19