我在 rails 上建站,目前遇到了问题,请大家帮忙看看,之前把图片上传到七牛云都是正常显示的。谢谢。 我将上传到阿里云 oss 的图片地址复制到浏览器是可以打开的。
bucket 设为公共读。
安装的 gem 如下:
gem 'carrierwave'
gem 'mini_magick'
gem 'carrierwave-qiniu'
gem 'qiniu-rs'
gem 'figaro'
gem 'rest-client'
gem 'carrierwave-aliyun'
carrierwave.rb 配置如下
CarrierWave.configure do |config|
config.storage = :aliyun
config.aliyun_access_id = ENV["aliyun_access_id"]
config.aliyun_access_key = ENV["aliyun_access_key"]
config.aliyun_bucket = ENV["aliyun_bucket"]
config.aliyun_host = "https://xxx.oss-cn-shenzhen.aliyuncs.com" #oss 给我的外网域名,我没有自定义
config.aliyun_internal = false
config.aliyun_area = "cn-shenzhen"
config.aliyun_private_read = false
end
image_uploader.rb 配置如下
version :thumb do
process resize_to_fit: [50, 50]
end
version :small do
process resize_to_fit: [250, 250]
end
version :middle do
process resize_to_fit: [800, 600]
end
version :large do
process resize_to_fit: [1200, 768]
end
if Rails.env.production? #远端
storage :aliyun
elsif Rails.env.development? #本地
storage :file
end
view 是这样设置的
<% if introduction.image.present? %>
<%= link_to image_tag(introduction.image.small.url, class: "img-responsive center-block introduction-image"), introduction_path(introduction) %>
<% else %>
<%= link_to image_tag("http://placehold.it/250x250&text=No Pic", class: "img-responsive center-block"), introduction_path(introduction) %>
<% end %>