Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

old files are not deleted when a new file is uploaded #125

Closed
Goltergaul opened this issue Mar 21, 2014 · 7 comments
Closed

old files are not deleted when a new file is uploaded #125

Goltergaul opened this issue Mar 21, 2014 · 7 comments

Comments

@Goltergaul
Copy link

i'm using the master branch version of this gem and when i upload an image and upload a second one later, then the old image file remains in the upload directory and is not deleted

@rmm5t
Copy link
Member

rmm5t commented Mar 21, 2014

Does v0.7.0 exhibit the same behavior? What version of carrierwave are you tied to as well?

@Goltergaul
Copy link
Author

I am using carrierwave 0.10.0. I forgot to mention that I am using mongoid 4.0.0.beta1 (which is why I have to use the master branch of carrierwave-mongoid gem) So i suppose that is related to some change in mongoid

@rmm5t
Copy link
Member

rmm5t commented Mar 23, 2014

Just for clarity, the master branch of carrierwave-mongoid shouldn't be necessary for mongoid 4.0.0.

A combination of carrierwave-mongoid v0.7.0 and mongoid-grid_fs v1.9.2 should do this trick.

Nonetheless, for the issue reported here, a pull-request with a failing test case would really help.

@Goltergaul
Copy link
Author

i could not get a working failing test yet, mostly because i wanted to use my uploader config which uses rmagik, but the tests are not made to work with that config.

However my uploader config is:

class AvatarUploader < CarrierWave::Uploader::Base

  include CarrierWave::RMagick

  storage :file

  # Override the directory where uploaded files will be stored.
  def store_dir
    "shared/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Sets the cache dir for uploads
  def cache_dir
    Rails.root.join 'tmp/uploads'
  end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  def default_url
    ActionController::Base.helpers.asset_path("fallbacks/courier_avatar/" + [version_name, "default.png"].compact.join('_'))
  end

  # Process files as they are uploaded:
  process :resize_to_fill => [200, 200]

  # Create different versions of your uploaded files:
  version :thumb do
    process :resize_to_fill => [50, 50] 
  end

  # Add a white list of extensions which are allowed to be uploaded.
  def extension_white_list
    %w(jpg jpeg gif png)
  end

  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for     details.
  # def filename
  #   "something.jpg" if original_filename
  # end

end

also i mount that uploader in an embedded document:

module Users
  class CompanyUser
    include Mongoid::Document
    embedded_in :user

    mount_uploader :avatar, AvatarUploader
  end
end

class User
  include Mongoid::Document

  embeds_one :company_user, class_name: "Users::CompanyUser", cascade_callbacks: true, validate: true
end

@rmm5t
Copy link
Member

rmm5t commented Mar 24, 2014

Interesting. Do you think you could try CarrierWave::MiniMagick in your development environment to see if the problem still exhibits itself.

I'm okay with adding a development dependency on rmagick to catch an extra scenario, especially if there's a problem with how carrierwave-mongoid exhibits itself in that scenario.

Curious though, what was the deciding factor to go with RMagick? Carrierwave documentation advises against this and recommends MiniMagick instead.

@rmm5t
Copy link
Member

rmm5t commented Oct 9, 2016

Related to #159?

@rmm5t
Copy link
Member

rmm5t commented Oct 15, 2017

Closing this in favor of #159, because there is an example of a potential failing test case there to start a PR against.

@rmm5t rmm5t closed this as completed Oct 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants