You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
When I'm updating image from rails form, through update_attributes and carrierwave uploader, on cloudinary both: new and old images are kept. Is it possible to override this behavior?
Thanks in advance.
Could you maybe share a code snippet so we could verify we are on the same page?
Also if you could share the versions that are being used of your Ruby, Rails, Cloudinary GEM and CarrierWave installations we could take a closer look.
I have the same problem, updating an attachment through a fileupload creates a new file on cloudinary leaving the old one untouched. If I look at the carrier_wave.rb file, there is only a Cloudinary::Uploader.destroy call in the delete method, but no after_update functionality to destroy the old public_id.
I fixed it by adding a callback to my uploaders. Since carrierwave stores the public_id within an identifier with resource_type ... and the destructuring method is not modular, I choose to initialize a new CloudinaryFile object and call the delete method.
class CarrierWave::Uploader::Base
# has to be included before after :store
include Cloudinary::CarrierWave
after :store, :cleanup_changed
def cleanup_changed(_arg)
was_identifier = self.model.saved_changes[mounted_as][0]
unless was_identifier.nil?
was_file = CloudinaryFile.new(was_identifier, self)
was_file.delete
end
end
end
Activity
idobarnoam commentedon Jul 18, 2018
Hi @Nkadze
Could you maybe share a code snippet so we could verify we are on the same page?
Also if you could share the versions that are being used of your Ruby, Rails, Cloudinary GEM and CarrierWave installations we could take a closer look.
Nkadze commentedon Jul 19, 2018
@idobarnoam, Thanks for quick response,
Those are package versions:
Uploader:
Model:
Update Code:
or:
taragano commentedon Jul 19, 2018
Thank you @Nkadze. We're taking a look and we'll let you know of any insights.
toyflish commentedon Jul 27, 2018
I have the same problem, updating an attachment through a fileupload creates a new file on cloudinary leaving the old one untouched. If I look at the carrier_wave.rb file, there is only a Cloudinary::Uploader.destroy call in the delete method, but no after_update functionality to destroy the old public_id.
toyflish commentedon Jul 27, 2018
I fixed it by adding a callback to my uploaders. Since carrierwave stores the public_id within an identifier with resource_type ... and the destructuring method is not modular, I choose to initialize a new CloudinaryFile object and call the delete method.