CarrierWave / Cloudinary提供上传图片的网址

时间:2014-09-29 17:25:23

标签: ruby-on-rails carrierwave cloudinary

我正在从Paperclip转移到CarrierWave和Cloudinary,我希望将以前所有的图像存储在S3上,然后将其存储到Cloudinary中。

我目前的做法是这样做:

my_model.cloudinary_logo = open(my_model.logo.url)
my_model.save

但这迫使我下载文件然后上传到cloudinary,我不能只是给它提供网址吗?

另一种方法是:

cloudinary_uploaded_file = Cloudinary::Uploader.upload(my_model.logo.url)
my_model.write_attribute :c_image, "v#{cloudinary_uploaded_file['version']}/#{cloudinary_uploaded_file['public_id']}.#{cloudinary_uploaded_file['format']}"

但在我看来,这有点像hacky ......

1 个答案:

答案 0 :(得分:0)

如评论中提到的jcm,我们可以使用:remote_attribute_url。就那么简单! 所以代码变成了:

my_model.remote_c_image_url = my_model.logo.url
my_model.save