我正在尝试将图像从本地文件系统迁移到dropbox,因此我使用carrierwave dropbox gem将所有图像移动到dropbox。我能够存储从我的应用程序上传的新图像。我正试图移动现有的图像。
我正在使用Article.first.avatar?检查图像是否存在的方法,我已经在很多地方使用这种方法来处理我的应用程序中不同大小的图像。
当我使用上述方法来确定图像是否存在时,它总是在Dropbox中不存在图像时显示为true。看看我的控制台输出(2),
我的上传者:
class Avatar < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage: file
def store_dir
if model
"uploads/#{model.class.to_s.underscore}/#{model.id}/#{mounted_as}"
else
"uploads/#{mounted_as}/"
end
end
end
控制台输出(1)
>Article.first.avatar?
>false
#<AvatarUploader:0x007f9813f1fe70
@file=
#<CarrierWave::SanitizedFile:0x007f9813f1e688
@content_type=nil,
@file="/Users/work/project/app1/public/uploads/370/avatar/avatar.png",
@original_filename=nil>,
@model=
##Article model
@mounted_as=:avatar,
@storage=#<CarrierWave::Storage::File:0x007f9813f1fad8 @uploader=#<AvatarUploader:0x007f9813f1fe70 ...>>,
@versions={}>
我按如下方式更改了上传器:
class Avatar < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage: dropbox
def store_dir
if model
"uploads/#{model.class.to_s.underscore}/#{model.id}/#{mounted_as}"
else
"uploads/#{mounted_as}/"
end
end
end
控制台输出(2)
>Article.first.avatar?
>true
#<AvatarUploader:0x007f8574143ee8
@file=
#<CarrierWave::Storage::Dropbox::File:0x007f8574143308
@client=
#<DropboxClient:0x007f8574143420
@root="dropbox",
@session=
#<DropboxSession:0x007f8574143498
@access_token=#<OAuthToken:0x007f8574143470 @key="123453333", @secret="22222222222">,
@consumer_key="abcdeafs",
@consumer_secret="asdfasfj",
@locale=nil,
@request_token=nil>>,
@config=
{:app_key=>"asdfasfasf",
:app_secret=>"asdfkasfksf",
:access_token=>"adfkjasfkhs",
:access_token_secret=>"aksdfkhsfksf",
:access_type=>"dropbox",
:user_id=>"292929292"},
@path="uploads/images/370/avatar.png",
@uploader=#<AvatarUploader:0x007f8574143ee8 ...>>,
@model=
#Artcle Model>,
@mounted_as=:image,
@storage=
#<CarrierWave::Storage::Dropbox:0x007f8574143c90
@config=
{:app_key=>"asdfasfasf",
:app_secret=>"asdfkasfksf",
:access_token=>"adfkjasfkhs",
:access_token_secret=>"aksdfkhsfksf",
:access_type=>"dropbox",
:user_id=>"292929292"},
@dropbox_client=
#<DropboxClient:0x007f8574143420
@root="dropbox",
@session=
答案 0 :(得分:0)
我在黑暗中的刺是在Carrierwave中,它返回的正常文件类(已清理文件)通过检查文件是否存在来响应空:
在carrierwave dropbox gem中,File类(https://github.com/robin850/carrierwave-dropbox/blob/master/lib/carrierwave/storage/dropbox.rb#L45)没有实现这一点。我猜你是否重新开课并添加了
module CarrierWave
module Storage
class Dropbox < Abstract
class File
def empty?
# use dropbox API to get the file and check the presence here
end
end
end
end
end
它可能有用吗?