Giter Club home page Giter Club logo

activestorage-uploadcare's Introduction

ActiveStorage::Uploadcare

Installation and usage

  1. Install ActiveStorage
rails active_storage:install
rails db:migrate
  1. Add this line to your application's Gemfile:
gem 'activestorage-uploadcare', git: 'https://github.com/uploadcare/activestorage-uploadcare.git'
  1. And then execute these commands to install the gem and create the migration:
bundle
rails generate migration CreateActiveStorageKeysUploadcareUuids key:string:uniq:index uuid:string:uniq:index
rails db:migrate
  1. Configure your Uploadcare project in config/storage.yml:
uploadcare_public_project:
  service: uploadcare
  public_key: <%= ENV['UPLOADCARE_PUBLIC_KEY'] %>
  secret_key: <%= ENV['UPLOADCARE_SECRET_KEY'] %>
  public: true

uploadcare_private_project:
  public: false
  cname: example.com
  signing_secret: YOUR_SIGNING_SECRET
  1. Set the service in config/environments/<environment>.rb:
config.active_storage.service = :uploadcare_public
  1. Now you can use ActiveStorage as usual:
class User < ApplicationRecord
  has_one_attached :avatar
end

user = User.create
user.avatar.attach(io: File.open('/path/to/file')
puts user.avatar.url
# will print something like:
# https://ucarecdn.com/0e8b1b1e-5b3e-4e4e-9b1b-1e5b3e4e4e9b/

Limitations and specifics

  1. ActiveStorage::Uploadcare doesn't support direct uploads. You need to upload files via your server.
  2. ActiveStorage has file variants feature. But Uploadcare has its own image transformations. For example, images are transformed on the fly, and automatically cached on the CDN. You don't need to worry about storing and processing variants. So, with ActiveStorage::Uploadcare service variant become redundant.

Testing

bundle
cp test/configurations.example.yml test/configurations.yml
UPLOADCARE_PUBLIC_KEY=YOUR_PK UPLOADCARE_SECRET_KEY=YOUR_SK bin/test

activestorage-uploadcare's People

Contributors

alxgsv avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.