Shrine::Storage::Uploadcare

Provides Uploadcare storage for Shrine.

Uploadcare offers file storage with a CDN and on-demand image processing, along with an advanced HTML widget for direct uploads.

Installation

gem "shrine-uploadcare", "~> 1.0"

Usage

require "shrine"
require "shrine/storage/uploadcare"

uploadcare_options = {
  public_key:  "...",
  private_key: "...",
}

Shrine.storages = {
  cache: Shrine::Storage::Uploadcare.new(**uploadcare_options),
  store: Shrine::Storage::Uploadcare.new(**uploadcare_options),
}

Direct uploads

The Shrine::Storage::Uploadcare class implements the #presign method, so it should work with Shrine's presign_endpoint plugin and Uppy's AwsS3 plugin.

If that doesn't work, you can always use Shrine's upload_endpoint plugin with Uppy's XHRUpload plugin.

URL operations

You can generate Uploadcare's URL operations by passing options to #url:

photo.image_url(resize: "200x")
photo.image_url(crop: ["200x300", :center])

Metadata

Uploadcare metadata is automatically stored on upload:

user = User.create(avatar: image_file)
user.avatar.metadata
# {
#   "height" => 45,
#   "width" => 91,
#   "geo_location" => null,
#   "datetime_original" => null,
#   "format" => "PNG",
#   ...
# }

Clearing storage

You can delete all files from the Uploadcare storage in the same way as you do with other storages:

uploadcare = Shrine::Storage::Uploadcare.new(**options)
# ...
uploadcare.clear!

Contributing

Firstly you need to create an .env file with Uploadcare credentials:

# .env
UPLOADCARE_PUBLIC_KEY="..."
UPLOADCARE_SECRET_KEY="..."

Afterwards you can run the tests:

$ rake test

License

MIT