[英]Carrierwave S3 Keep File when Editing
I have Carrierwave working to upload images to my site and storing them on S3. 我让Carrierwave致力于将图像上传到我的站点并将其存储在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.
我想让现有图像继续使用,除非用户“选择”上传新图像。
In the carrierwave wiki , you have a section How to: Keep uploaded files (for a specific uploader) . 在carrierwave Wiki中 ,有一个部分如何:保留上传的文件(对于特定的上传者) 。 I don't know if this works with S3, but you may give it a try.
我不知道这是否适用于S3,但是您可以尝试一下。
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
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.
尽管UI不能反映出图像仍然存在,但用户不需要再次上传图片。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.