Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ovenbits/breadbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

51 Commits

Repository files navigation

Code Climate Dependency Status

Breadbox

A simple wrapper interface for uploading files to Dropbox or Amazon S3

Disclaimer

  • This is a simple and fast implementation - Issues and PRs welcome.
  • Currently tested on Ruby 2.1.2

Installation

Add this line to your application's Gemfile:

gem 'breadbox'

And then execute:

$ bundle

Or install it yourself as:

$ gem install breadbox

Setup for Dropbox

2. Add to your initializers:

# config/initializers/breadbox.rb
Breadbox.configure do |config|
 config.dropbox_access_token = xxxxxxx # THIS IS REQUIRED
 config.provider = :dropbox # THIS IS REQUIRED
end

Setup for S3

1. Get your AWS Credentials

3. Add to your initializers

# config/initializers/breadbox.rb
Breadbox.configure do |config|
 config.s3_region = xxxxxxxx # OPTIONAL - defaults to "us-east-1"
 config.s3_bucket = "name of the bucket" # THIS IS REQUIRED
 config.s3_secret_access_key = xxxxxx # THIS IS REQUIRED
 config.s3_access_key_id = xxxxxxx # THIS IS REQUIRED
 config.provider = :s3 # THIS IS REQUIRED
end

(Optional) Configure your root directory for uploading files

By default - the root path will be the root directory of your [DropBox folder or S3 Bucket]. You can, however, change the root path to be anything you want.

Note: You have to prefix the folder you want with a /, ex: /uploads/my-files

# config/initializers/breadbox.rb
Breadbox.configure do |config|
 config.root_path = "/uploads/my-files"
 # ... more configurations ...
end

Usage

Parameters:

  • path: defaults to nil, but this is where you put a custom folder if you so wish (in relation to your root_path, which if you didn't configure in your initializer, will be your root Dropbox folder /.
  • filename: defaults to the name of the file you are uploading, but you can specify a custom name here.
  • file: The file object that you are uploading, ex: `file = File.open('./path-to-local-file').
  • cleanup: defaults to false, but if you pass true - it will remove the local file after uploading.
  • public: defaults to false. Pass true if you'd like to set the file permission level to world readable.
  • content_type: S3 knows how to handle most file types, but occasionally, you may need to specify your own
# to upload a file to [Dropbox Folder or S3 Bucket]/uploads/my-cool-file.jpg
# and remove it after upload
file = File.open("./tmp/my-cool-file.jpg")
Breadbox.upload(path: "uploads", file: file, cleanup: true)

Running Tests

Just run rake in the project root.

Console

For a REPL console, run rake console in the project root.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/breadbox/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

A simple wrapper for uploading files to Dropbox or Amazon S3

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

Languages

AltStyle によって変換されたページ (->オリジナル) /