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

Updating a file where version has overridden full_filename fails #178

Open
toby-brilliant opened this issue Nov 14, 2023 · 1 comment
Open

Comments

@toby-brilliant
Copy link

toby-brilliant commented Nov 14, 2023

tl;dr: When a file initially exists and that is updated, any versions with overridden full_filename will not make it out of the temp directory


My code looks like this:

class LogoUploader < CarrierWave::Uploader::Base
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :thumb
  version :small
  version :medium

  version :png do
    def full_filename(for_file = model.logo.file)
      "png_logo.png"
    end
  end
end

Blank slate

> s.update!(logo: nil)
> s.logo.url
=> nil
aws s3 ls s3://our-great-bucket/uploads/store/logo/2076/
<nothing here>

Uploading a file initially

> s.logo = File.open("app/assets/images/fulfillment/details_icon.png")
> s.logo.url
=> "https://s3.us-west-1.amazonaws.com/our-great-bucket/uploads/tmp/1699985556-433121775682744-0001-0914/details_icon.png"
aws s3 ls s3://our-great-bucket/uploads/tmp/1699985556-433121775682744-0001-0914/
2023-11-14 13:12:37     218814 details_icon.png
2023-11-14 13:12:40     218814 medium_details_icon.png
2023-11-14 13:12:40     218814 png_details_icon.png
2023-11-14 13:12:39     218814 small_details_icon.png
2023-11-14 13:12:38     218814 thumb_details_icon.png

Great success - the original image plus 4 versions are all in the temp directory.

> s.save!
> s.logo.url
=> "https://s3.us-west-1.amazonaws.com/our-great-bucket/uploads/store/logo/2076/details_icon.png"
aws s3 ls s3://our-great-bucket/uploads/store/logo/2076/
2023-11-14 13:14:36     218814 details_icon.png
2023-11-14 13:14:37     218814 medium_details_icon.png
2023-11-14 13:14:38     218814 png_logo.png
2023-11-14 13:14:37     218814 small_details_icon.png
2023-11-14 13:14:36     218814 thumb_details_icon.png

Everything is as it should be - the original image plus 4 versions are all in the permanent directory

Updating the file

Starting from the step above, where the logo is populated:

> s.logo = File.open("/Users/tobymurray/Downloads/fulfillment_details.png")
> s.logo.url
=> "https://s3.us-west-1.amazonaws.com/our-great-bucket/uploads/tmp/1699985842-274372010805457-0002-5124/fulfillment_details.png"
aws s3 ls s3://our-great-bucket/uploads/tmp/1699985842-274372010805457-0002-5124/
2023-11-14 13:17:24     337881 fulfillment_details.png
2023-11-14 13:17:28     337881 medium_fulfillment_details.png
2023-11-14 13:17:28     337881 png_fulfillment_details.png
2023-11-14 13:17:27     337881 small_fulfillment_details.png
2023-11-14 13:17:26     337881 thumb_fulfillment_details.png

Everything is as it should be - the original image plus 4 versions are all in the temp directory

s.save!
aws s3 ls s3://our-great-bucket/uploads/store/logo/2076/

2023-11-14 13:18:44     337881 fulfillment_details.png
2023-11-14 13:18:46     337881 medium_fulfillment_details.png
2023-11-14 13:18:45     337881 small_fulfillment_details.png
2023-11-14 13:18:45     337881 thumb_fulfillment_details.png

Missing png_fulfillment_details.png.

Dependencies

aws-sdk-s3 (1.136.0)
carrierwave (3.0.4)
carrierwave-aws (1.6.0)
rails (6.0.6.1)
ruby "2.7.8"

@toby-brilliant
Copy link
Author

Potentially related to the comment here: #153 (comment)

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

1 participant