No commit activity in last 3 years
No release in over 3 years
Provides Uploadcare storage for Shrine.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

~> 5.0
>= 3.2, < 5
>= 3.0.0.rc, < 4
 Project Readme

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