镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Old image kept on cloudinary #311

Open

Description

@Nkadze

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.

Activity

  1. idobarnoam commented on Jul 18, 2018

    @idobarnoam

    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.

  2. Nkadze commented on Jul 19, 2018

    @Nkadze
    Author

    @idobarnoam, Thanks for quick response,

    Those are package versions:

    ruby '2.3.1'
    'rails', '~> 5.1.5'
    cloudinary (1.9.1)
    carrierwave (1.2.3)
    

    Uploader:

    class ImageUploader < CarrierWave::Uploader::Base
      include Cloudinary::CarrierWave
    
      process resize_to_fit: [1920, 1080]
    
      version :small do
        cloudinary_transformation \
        gravity:      'auto',
        width:        150,
        height:       100,
        crop:         'fill',
        quality:      'auto',
        fetch_format: :auto
      end
    
    end

    Model:

    mount_uploader :featured_image, ImageUploader

    Update Code:

    obj.update_attributes(remote_featured_image_url: url)

    or:

    @model.update(model_params)
    #--------------
    def model_params
       params.require(:model).permit(:name, :featured_image, :featured_image_cache)
    end
  3. taragano commented on Jul 19, 2018

    @taragano
    Collaborator

    Thank you @Nkadze. We're taking a look and we'll let you know of any insights.

  4. toyflish commented on Jul 27, 2018

    @toyflish

    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.

  5. toyflish commented on Jul 27, 2018

    @toyflish

    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
    
  6. reopened this on Aug 28, 2018
  7. assigned and unassigned on Aug 28, 2018
  8. removed their assignment
    on Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions