首页 > 解决方案 > 使用carrierwave从Rails将图像上传为私有云

问题描述

我正在开发一个 Rails 网站,该网站需要在 Cloudinary 上将图像上传为私有。现在它在 Cloudinary 上公开上传图片。

我可以使用以下命令在 Cloudinary 上手动将文件上传为私有文件:

Cloudinary::Uploader.upload("Photo No. 11.jpeg", :type => :private)

图像变得私密且无法访问。

有没有办法用 Carrierwave 做到这一点?

标签: ruby-on-railscarrierwave

解决方案


你应该在你的上传器中做这样的事情

class PictureUploader < CarrierWave::Uploader::Base  
  include Cloudinary::CarrierWave  
  make_private # This will make sure you're images are uploaded as private
  eager

  version :medium do    
    process :resize_to_fill => [164, 164, 'North']
    process :convert => 'jpg'
    cloudinary_transformation :quality => 80
  end
end

推荐阅读