Class: SnapImage::Cloudinary::Storage
- Inherits:
-
Object
- Object
- SnapImage::Cloudinary::Storage
- Defined in:
- lib/snapimage/adapters/cloudinary/storage.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ Storage
constructor
A new instance of Storage.
-
#store(filename, file, options = {}) ⇒ Object
Stores the file in the given directory and returns the publicly accessible URL.
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, = {}) ext = File.extname(filename) basename = File.basename(filename, ext) public_id = "#{basename}_#{rand(9999)}" public_id = File.join([:directory], public_id) if [:directory] response = ::Cloudinary::Uploader.upload(file, public_id: public_id) ::Cloudinary::Utils.cloudinary_url(public_id + ext) end |