Project

breadbox

0.0
No commit activity in last 3 years
No release in over 3 years
This gem is just to provide some niceties for uploading with the DropBox and Amazon SDKs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 0.10
>= 0
~> 3.1

Runtime

~> 2.1.7
~> 1.6.4
 Project Readme

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