【发布时间】:2018-10-31 17:33:46
【问题描述】:
所以我有一个在开发中运行良好的 Web 应用程序,并且使用 carrierwave 和 imagemagick 我对需要上传的照片进行了一些更改。问题是,当我在 heroku 上询问照片的主要版本时,它仍然给我拇指版本
class BannerUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
if Rails.env.development?
storage :file
else
storage :dropbox
end
def store_dir
if version_name.nil?
"uploads/#{model.class.to_s.underscore}/#{mounted_as}"
else
"uploads/#{model.class.to_s.underscore}/#{mounted_as}_#{version_name}"
end
end
process convert: :jpg
process :crop
process resize_to_limit: [1200, 260]
def crop
if model.crop_x.present?
manipulate! do |img|
x = model.crop_x.to_i
y = model.crop_y.to_i
w = model.crop_w.to_i
h = model.crop_h.to_i
r = model.crop_r.to_i
img.rotate r
img.crop([[w, h].join('x'), [x, y].join('+')].join('+'))
end
end
end
version :thumb do
process resize_to_fill: [640, 320]
end
def extension_whitelist
%w(jpg jpeg png)
end
def filename
if original_filename
"#{secure_token}.#{file.extension}"
elsif file
file.filename
end
end
protected
def secure_token
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
end
end
这是我的上传者
然后在我看来,我有 image_tag(model.banner_url(:thumb) 来获取拇指版本,image_tag @model.banner_url 来获取大版本。问题是我本地机器上的第二个运行得很好,但是在 heroku 上它给了我第一个相同的图像。它确实创建了正确的文件夹和文件,并且确实裁剪了它们,但它没有检索到正确的文件夹和文件。我正在使用
gem 'dropbox-sdk-v2', '~> 0.0.3'
gem 'carrierwave-dropbox', '~> 2.0'
作为 heroku 存储,显然有一个 Dropbox 帐户
【问题讨论】:
标签: ruby-on-rails heroku ruby-on-rails-5 dropbox carrierwave