I've followed the following steps and I've read/write to my Dropbox.
Title:
Using Dropbox with Ruby On Rails on Heroku
Objective:
Heroku does not offer a persist storage and suggests amazon s3 which needs a credit card to register and use it.
So Dropbox may be a good replacement at least for training and development level.
Steps:
1. Install sdk
command: gem install Dropbox-sdk
link: https://www.Dropbox.com/developers-v1/core/sdks/ruby
Create a Dropbox accout if you don't have one
link: https://www.Dropbox.com
action: create an account
Create an App on Dropbox platform
link: https://www.Dropbox.com/developers/apps
action: Specify a name for you app and you will given App Key and App Secret
remarks: App can have access to whole Dropbox or just a specific folder
Try this basic tutorial to test what you can do
link: https://www.Dropbox.com/developers-v1/core/start/ruby
action:
a.replace 'INSERT_APP_KEY' and 'INSERT_APP_SECRET' with your App keys
b.Execute ruby script
c.Browse given link to authorize and generate access token
d.Copy and paste the code on the script console and continue
caution:
The script is trying to load a local file first, so be sure you create it on proper path
Execution steps:
a.Authenticate
b.Upload file
c.Download file and write it to local
You could generate access token on your app home and use it instead of everytime generating it with APP_KEY & APP_SECRET
- To Use Dropbox with rails (CarrierWare)
link: https://github.com/robin850/carrierwave-Dropbox
steps:
6a. include gem 'carrierwave-Dropbox' in your Gemfile
6b. run 'bundle install'
6c. run
rake Dropbox:authorize APP_KEY=app_key APP_SECRET=app_secret ACCESS_TYPE=Dropbox|app_folder
6d. set appropriate settings in your ImageUploader file (CustomNameUploader)
class ImageUploader < CarrierWave::Uploader::Base
storage :Dropbox
def initailize
CarrierWave.configure do |config|
...
# Dropbox settings
...
end
end
end
7. If your are on a source control it will be better choice to set values as env vars and then use them instead.
The link shows how to set or persist environment variables in ubuntu.
link: https://help.ubuntu.com/community/EnvironmentVariables
On production (heroku) set environment vars like follows:
usage: heroku config:set ACCESS_TOKEN_SECRET='your_app_access_token_secret'
link: https://devcenter.heroku.com/articles/config-vars
It will be a good practice to create carrierwave.rb file in config/initializers and place all setting in that file
also it can be set conditionally for production and development
Beware that Dropbox may be slow and you will get application error, so try it with smaller files and load them
with pagination if they are too many.
This is a published link on linkedin:
https://www.linkedin.com/pulse/using-dropbox-ruby-rails-heroku-serjik-isagholian?trk=prof-post