This gem allows you to easily upload your medias on Dropbox using the awesome CarrierWave gem.
First, you have to create a Dropbox app. You can either create a "full dropbox" or "app folder" application. Please see this wiki for further information and gotchas.
Then, add this line to your application's Gemfile:
gem 'carrierwave-dropbox'
Run bundle
.
Grab your access token for your DB app. To make a DB app / generate token, go here.
CarrierWave.configure do |config|
config.dropbox_access_token = ENV["ACCESS_TOKEN"]
end
Note: It's advisable not to directly store the credentials in your files especially if you are using a SCM (e.g. git). You should store these values in environment variables for instance like in the above example.
Then you can either specify in your uploader files the storage or define it
globally through CarrierWave.configure
:
class ImageUploader < CarrierWave::Uploader::Base
storage :dropbox
end
Unlike typical CarrierWave
storage engines, we do not assume an uploaded file
will always be at the same path, as DB UI users may move files around. As such,
this version of this gem relies on the file id. There are two significant
implications to this approach:
- The
#store_path
and#store_dir
methods are not guaranteed to be accurate after the initial file upload. We do not overwrite these methods as the end user will often overwrite these methods to specify where the file should initially be stored. - The default
#filename
method is not accurate, as we are storing the DB id, rather than the name of the file. I recommend that end users overwrite the#filename
method to delegate to theCarrierWave::Storage::Dropbox::File
interface. Example:
MyUploader < CarrierWave::Uploader::Base
storage :dropbox
def filename
if original_filename
# perform any file name manipulation on initial upload
elsif file
file.filename
end
end
end
This project is highly based on these two gems:
Thanks to their respective authors and contributors!
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Please see the LICENSE
file for further information.