Reputation: 4268
Well, I'm using carrierwave and generating versions (thumbnails) with it. The storage backend is Amazon S3.
class Image < ActiveRecord::Base
mount_uploader :attachment, ImageUploader
end
When I call Image.find(1).destroy, the original file is removed from S3:
but a version of it stills there:
I'm suspecting of the method def full_filename(for_file)
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
include CarrierWave::MiniMagick
include CarrierWaveDirect::Uploader
def store_dir
"assets"
end
def cache_dir
"#{Rails.root}/tmp/images"
end
version :square do
process resize_to_fill: [200, 200]
def full_filename(for_file)
ext = File.extname(for_file)
base_name = for_file.chomp(ext)
[base_name, version_name].compact.join('_') + ".jpg"
end
end
end
Thanks in advance!
Upvotes: 1
Views: 382
Reputation: 53018
Replace your version definition as below:
version :square do
process resize_to_fill: [200, 200]
end
You do not need to define the file name as Carrierwave will make a new version of file with square_
prefix. So, its unique anyway.
When you call Image.find(1).destroy
, Carrierwave destroys the original file and then looks for a file with square_*
prefix to delete.
Upvotes: 4