Giter Site home page Giter Site logo

paperclip-dropbox's Introduction

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

paperclip-dropbox's People

Contributors

cesarfigueroa avatar digitalcora avatar dilshod avatar dougbradbury avatar dukz avatar janko avatar jdtanacredi 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.