Class: SnapImage::Cloudinary::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/snapimage/adapters/cloudinary/storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Storage

Returns a new instance of Storage.



4
5
6
# File 'lib/snapimage/adapters/cloudinary/storage.rb', line 4

def initialize(config)
  @config = config
end

Instance Method Details

#store(filename, file, options = {}) ⇒ Object

Stores the file in the given directory and returns the publicly accessible URL. Options:

  • directory - directory to store the file in



12
13
14
15
16
17
18
19
# File 'lib/snapimage/adapters/cloudinary/storage.rb', line 12

def store(filename, file, options = {})
  ext = File.extname(filename)
  basename = File.basename(filename, ext)
  public_id = "#{basename}_#{rand(9999)}"
  public_id = File.join(options[:directory], public_id) if options[:directory]
  response = ::Cloudinary::Uploader.upload(file, public_id: public_id)
  ::Cloudinary::Utils.cloudinary_url(public_id + ext)
end