我正在尝试上传图像到谷歌驱动器使用神社。我遵循了这个gem https://github.com/verynear/shrine-google_drive_storage中的说明。
我将这个宝石添加到我的项目中
gem 'shrine'
gem 'shrine-google_drive_storage'这是我的config/shintine.rb
require "shrine"
require "shrine/storage/google_drive_storage"
Shrine.storages = {
cache: Shrine::Storage::GoogleDriveStorage.new(prefix: "cache"),
store: Shrine::Storage::GoogleDriveStorage.new(prefix: "store"),
}
Shrine::Storage::GoogleDriveStorage.new(
prefix: "store",
google_drive_client_secret_path: "#{Rails.root}/config/client_secret.json",
drive_public_folder_id: '0Bz_kkknizZmZRXZzeXdua1FNUXc',
google_drive_options: {
path: proc { |style| "#{id}_#{photo.original_filename}_#{style}" },
},
)但是当我尝试上传图片时,我得到了这个错误信息
NameError (undefined local variable or method `content_type' for #<Shrine::Storage::GoogleDriveStorage:0x00000004009868>):有人知道我哪里搞错了吗?
发布于 2017-11-04 04:02:07
您应该使用所有必需的选项初始化Shrine::Storage::GoogleDriveStorage,并将其分配给相应的神殿存储(cache和store),如下所示:
Shrine.storages = {
cache: Shrine::Storage::GoogleDriveStorage.new(
prefix: "cache",
google_drive_client_secret_path: "#{Rails.root}/config/client_secret.json",
drive_public_folder_id: '0Bz_kkknizZmZRXZzeXdua1FNUXc',
google_drive_options: {
path: proc { |style| "#{id}_#{photo.original_filename}_#{style}" }
}
),
store: Shrine::Storage::GoogleDriveStorage.new(
prefix: "store",
google_drive_client_secret_path: "#{Rails.root}/config/client_secret.json",
drive_public_folder_id: '0Bz_kkknizZmZRXZzeXdua1FNUXc',
google_drive_options: {
path: proc { |style| "#{id}_#{photo.original_filename}_#{style}" }
}
)
}之后,您需要创建一个uploader类,比如ImageUploader,并在您的模型中引入一个附件属性。具体操作步骤请参考janko-m/shrine quickstart section中的步骤以适应您的需求。
https://stackoverflow.com/questions/47097012
复制相似问题