0.0
No commit activity in last 3 years
No release in over 3 years
Extends Paperclip with Imgur storage
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.2.1
 Project Readme

Paperclip::Imgur

This gem extends Paperclip with Imgur storage. It's been tested with Paperclip 3.3.1, 4.3 and 5.1.

If you want Paperclip Dropbox support, have a look at this great gem.

Installation

Add this line to your application's Gemfile:

gem 'paperclip-imgur'

And then run:

$ bundle install

Usage

Tell your typical model™ to use Imgur as storage:

class User < ActiveRecord::Base
  has_attached_file :avatar, storage: :imgur
  validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\z/
end

Credentials

The credentials to upload and delete images from Imgur will be read from #{Rails.root}/config/imgur.yml. This file must contain the following keys:

client_id: 'CLIENT_ID'
client_secret: 'CLIENT_SECRET'
access_token: 'ACCESS_TOKEN'
refresh_token: 'REFRESH_TOKEN'
use_ssl: false

use_ssl is an optional, boolean key. When omitted, it's considered as false.

Get these keys with:

rake imgur:authorize CLIENT_ID='CLIENT_ID' CLIENT_SECRET='CLIENT_SECRET'

Please refer to the API client gem documentation for more information on this. Create an application if you don't have those client keys yet.

You can also specify the credentials per model attribute, using a hash:

has_attached_file :avatar, storage: :imgur, imgur_credentials: {client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET', access_token: 'ACCESS_TOKEN', refresh_token: 'REFRESH_TOKEN'}

…or path to a YAML file

has_attached_file :avatar, storage: :imgur, imgur_credentials: 'path.to/file.yml'

…or a File itself

has_attached_file :avatar, storage: :imgur, imgur_credentials: File.open('path.to/file.yml', 'r')

Use attachment in views

The image is available in your views in three different sizes:

<%= image_path @user.avatar %>
<%= image_path @user.avatar.url(:small) %>
<%= image_path @user.avatar.url(:large) %>

Deleting images

To delete an image, follow the usual Paperclip procedure:

@user.avatar = nil
@user.save

Testing

Run specs with

rspec