0

I am trying to upload images to google drive using Shrine. I followed instructions from this gem https://github.com/verynear/shrine-google_drive_storage

I added this gems to my project

gem 'shrine'
gem 'shrine-google_drive_storage'

This is my config/shrine.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}" },
      },
)

but when I try to upload image I get this error message

NameError (undefined local variable or method `content_type' for #<Shrine::Storage::GoogleDriveStorage:0x00000004009868>):

Does somebody know where I made mistake?

Mišel Ademi
  • 187
  • 4
  • 15
  • You're not doing anything wrong, except what Wasif already pointed out. It seems that shrine-google_cloud_storage wasn't really tested properly, you should open a ticket in the repo: https://github.com/verynear/shrine-google_drive_storage – Janko Nov 09 '17 at 03:25

1 Answers1

0

You should initialize Shrine::Storage::GoogleDriveStorage with all the required options and assign to corresponding Shrine storages (cache and store) like so:

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}" }
    }
  )
}

After that, you need to create an uploader class, say, ImageUploader and introduce an attachment attribute in your model. For detailed instructions, please follow the steps in janko-m/shrine quickstart section to adapt to your need.

Wasif Hossain
  • 3,900
  • 1
  • 18
  • 20