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

Version 3.0.0 deduplicates file names even when not needed #2670

Closed
Fs00 opened this issue Jul 5, 2023 · 4 comments
Closed

Version 3.0.0 deduplicates file names even when not needed #2670

Fs00 opened this issue Jul 5, 2023 · 4 comments

Comments

@Fs00
Copy link

Fs00 commented Jul 5, 2023

In our application we have an uploader set up like the following:

class AttachmentUploader < CarrierWave::Uploader::Base
  storage :file

  def store_dir
    "#{Rails.configuration.fs_root}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
end

which stores file attachments in a separate sub-folder for each record (notice #{model.id} at the end of the path).
When we duplicate a record that has an attachment with dup, we've noticed that the duplicated record attachment gets the suffix added to the filename, even though it's stored in a different folder compared to the original one and therefore there's no need to add the suffix.

If we force the uploader not to deduplicate filenames by overriding the following function (which admittedly looks a bit hacky and we'd rather not do that):

def deduplicated_filename
  filename
end

the issue disappears.

@Paul-Yves
Copy link

We got a very similar issue, when we reupload a file with an identical name, the saved file has duplicate name (eg example(2).png), but what is worse is that the uploader is still looking for the original filename without duplication, and it does no longer exist on our s3 so the picture is not available anymore

@mshibuya
Copy link
Member

mshibuya commented Jul 9, 2023

Thank you for reporting. This should be fixed by b732acd, so please try.

@GabrielKoehler
Copy link

Hi, in my uploader i've got the same issue.

My Carrierwave version is (3.0.7) and i using storage :fog, but the file still generates with suffix.

class BaseUploader < CarrierWave::Uploader::Base
  if Rails.env.in? %w[production blue staging]
    storage :fog
  else
    storage :file
  end
  
  def store_dir
    if Rails.env.production? || Rails.env.blue?
      "uploads/#{model.class.to_s.underscore}/#{model.id}"
    else
      "uploads-#{Rails.env}/#{model.class.to_s.underscore}/#{model.id}"
    end
  end
end
class CertificateUploader < BaseUploader
  def filename
    'certificate.pdf'
  end
end

The first time i try generate a new certificate, work's like a charm, but, if i retry to generate a new certificate file "certificate.pdf", my new certificate receives the sufix, like "certificate(2).pdf".

@mshibuya
Copy link
Member

@GabrielKoehler Yours should be unrelated to this, and is expected. See #2712 (comment) for reasoning.

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

4 participants