• This repository has been archived on 04/May/2019
  • Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[OBSOLETE] Extends Paperclip with Dropbox storage.

This gem is not maintained anymore and became obsolete. Over time Dropbox made some significant changes to its API, which breaks this gem's core functionality. You shouldn't be using it anymore.

While we're here, you also shouldn't be using Paperclip anymore, you should use Shrine instead.


Paperclip Dropbox

This gem extends Paperclip with Dropbox storage.

Setup

gem "paperclip-dropbox", ">= 1.1.7"

Example:

class User < ActiveRecord::Base
  has_attached_file :avatar,
    :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :dropbox_options => {...}
end

Your config/dropbox.yml:

app_key: "..."
app_secret: "..."
access_token: "..."
access_token_secret: "..."
user_id: "..."
access_type: "dropbox|app_folder"

You can also pass a Proc to :dropbox_credentials, if you want the credentials to be dynamically evaluated.

In order to fill these in, you must create a Dropbox app and authorize it. There are two types of Dropbox apps: App folder or Full Dropbox. You can read about the differences and gotchas in this wiki. When you decide, don't forget to put "dropbox" or "app_folder" as the :access_type in your credentials.

After you have created an app, you will be given the "App key" and "App secret". Provide these and the access type to the authorization Rake task:

$ rake dropbox:authorize APP_KEY=your_app_key APP_SECRET=your_app_secret ACCESS_TYPE=dropbox|app_folder

For non-Rails projects, you must require this task in your Rakefile:

# Rakefile
load "paperclip/dropbox/tasks.rake"

Follow the instructions, and it will authorize the Dropbox app and output the rest of the credentials. Then you can fill in the rest of config/dropbox.yml.

And that's it. Everything should work now :)

The :dropbox_credentials option

:dropbox_credentials => Rails.root.join("config/dropbox.yml")
# or
:dropbox_credentials => {app_key: "foo", app_secret: "bar", ...}

For the list of required credentials, take a look at the config/dropbox.yml above.

The YAML file supports ERB:

app_key: <%= ENV["DROPBOX_APP_KEY"] %>

And it supports environment nesting (just like database.yml):

development:
  app_key: "..."
  ...
production:
  app_key: "..."
  ...

The :dropbox_options option

This is a hash containing any of the following options:

  • :environment โ€“ String, the environment name to use for selecting namespaced credentials in a non-Rails app

For example:

class User < ActiveRecord::Base
  has_attached_file :avatar,
    :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :dropbox_options => {environment: ENV["RACK_ENV"]}
end

In Rails you don't need to specify it.

The :dropbox_visibility option

This is a string "public" (default) or "private".

  • "public" - Files will be placed in your "Public" directory in dropbox and will the public urls will be used to access the files (not http request required to get a url for the file)
  • "private" - Files can be placed in any dropbox directory (set your :path attachment option) and private, expiring urls (4 hours) will be generated each time you access this file. Private can only be used with the 'dropbox' access type.
class User < ActiveRecord::Base
  has_attached_file :avatar,
    :storage => :dropbox,
    :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
    :dropbox_visibility => 'public'
end

The :path option

To change the path of the file, use Paperclip's :path option:

:path => ":style/:id_:filename"  # Defaults to ":filename"

In "Full Dropbox" mode with "public" visibility it will automatically be searched in the Public folder, so there is not need to specify it.

URL options

If you want to force the browser to always download the file, you can use the :download option.

user.avatar.url(:download => true)

Check if the file exists

It may happen that a file on Dropbox gets deleted remotely. To check this in your application, you can use the #exists? method:

user.avatar.exists?
# user.avatar.exists?(style)

License

MIT License

More Repositories

1

down

Streaming downloads using Net::HTTP, http.rb or HTTPX
Ruby
1,024
star
2

image_processing

High-level image processing wrapper for libvips and ImageMagick/GraphicsMagick
Ruby
858
star
3

rodauth-rails

Rails integration for Rodauth authentication framework
HTML
424
star
4

tus-ruby-server

Ruby server for tus resumable upload protocol
Ruby
215
star
5

as-duration

Extraction of ActiveSupport::Duration from Rails
Ruby
125
star
6

sequel-activerecord_connection

Allows Sequel to reuse Active Record's database connection
Ruby
121
star
7

uppy-s3_multipart

Provides Ruby endpoints for aws-s3-multipart Uppy plugin
Ruby
63
star
8

tic-tac-toe

Play tic-tac-toe in your Terminal
Ruby
43
star
9

rodauth-demo-rails

Example Rails app that uses Rodauth for authentication
Ruby
36
star
10

rodauth-omniauth

OmniAuth login and registration for Rodauth authentication framework
Ruby
34
star
11

flickr-objects

An object-oriented wrapper for the Flickr API.
Ruby
28
star
12

shrine-example

[MOVED] Roda & Sequel demo for Shrine
JavaScript
19
star
13

rodauth-i18n

I18n integration and translations for Rodauth authentication framework
Ruby
16
star
14

flickrie

[DEPRECATED] A wrapper gem for the Flickr API
Ruby
14
star
15

rodauth-model

Password attribute and associations for Rodauth account model
Ruby
13
star
16

rodauth-pwned

Rodauth extension that checks user passwords against the Pwned Passwords API
Ruby
12
star
17

goliath-rack_proxy

[DEPRECATED] Goliath as a web server for your Rack app
Ruby
11
star
18

budget

Roda & Sequel app for tracking expenses
Ruby
8
star
19

janko.io

My blog
HTML
7
star
20

dotfiles

My dotfiles
Vim Script
6
star
21

hanami-rodauth-example

Example Hanami 2 application using Rodauth authentication framework
Ruby
6
star
22

musique

A Ruby gem for manipulating musical constructs.
Ruby
6
star
23

capybara-vs-webdriverio

Battle between Capybara and Webdriver.io for browser testing
JavaScript
5
star
24

flickr-login

A gem that provides Flickr authentication.
Ruby
2
star
25

roda-symbolized_params

A Roda plugin which symbolizes request params
Ruby
2
star
26

shrine-example-melbourne

Shrine tutorial application for Coder Factory Academy
Ruby
1
star
27

refactoring_practice

Ruby
1
star
28

sequel-jsonapi_eager

DEPRECATED in favor of `tactical_eager_loading` Sequel plugin
Ruby
1
star
29

rodauth-guest

Guest accounts for Rodauth authentication framework
Ruby
1
star