Scott S.
Scott S.

Reputation: 759

Carrierwave S3 Keep File when Editing

I have Carrierwave working to upload images to my site and storing them on S3.

However, whenever a user edits a record they have to upload the image again even when they don't need to change it. I want to let the existing image continue to be used unless the user "Chooses" to upload a new image.

Upvotes: 1

Views: 436

Answers (2)

Benjamin Crouzier
Benjamin Crouzier

Reputation: 41955

In the carrierwave wiki, you have a section How to: Keep uploaded files (for a specific uploader). I don't know if this works with S3, but you may give it a try.

To keep all uploaded files use an initializer like this:

CarrierWave.configure do |config|
  config.remove_previously_stored_files_after_update = false
end

If you want to configure that on a per-uploaded basis:

class AvatarUploader < CarrierWave::Uploader::Base
  configure do |config|
    config.remove_previously_stored_files_after_update = false
  end

  ...
end

Upvotes: 2

Scott S.
Scott S.

Reputation: 759

I don't know what I did, but this is working now. While the UI doesn't reflect that the image will still be there, the user doesn't need to upload the picture again.

Upvotes: 0

Related Questions