简体   繁体   English

rails4 carrierwave + S3添加新图像版本

[英]rails4 carrierwave + S3 adding new image version

I have a rails4 app, profile images are uploaded with carrierwave and served by S3. 我有一个rails4应用,配置文件图像是通过载波上传的,并由S3提供。

I used to have one image version ( base_thumb ) for resizing. 我曾经有一个图像版本( base_thumb )用于调整大小。 Now I'm trying to add user_thumb , but if I change the code from profile.avatar.url(:base_thumb) to profile.avatar.url(:user_thumb) then the image is not displayed to users who created profile earlier since that image version is not on S3. 现在,我尝试添加user_thumb ,但是如果我将代码从profile.avatar.url(:base_thumb)更改为profile.avatar.url(:user_thumb)则该图像不会显示给早于该图像创建了配置文件的用户版本不在S3上。

How can I solve this issue? 我该如何解决这个问题?

version :base_thumb do
  process :resize_to_fit => [85, 85]
end

version :user_thumb do
  process :resize_to_fit => [40, 40]
end

You'll need to create new versions of each different size. 您需要创建每个不同大小的新版本。 Carrierwave has a method for this. 载波有一种解决方法。

You can read the doc here: https://github.com/carrierwaveuploader/carrierwave#recreating-versions 您可以在此处阅读文档: https : //github.com/carrierwaveuploader/carrierwave#recreating-versions

but essentially you will run something like 但实际上您将运行类似

Profile.find_each do |profile|
  profile.avatar.recreate_versions! if profile.avatar?
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM