The paperclip-backblaze
provides a Paperclip storage adapter so that
attachments can be saved to Backblaze B2 Cloud Storage API.
It makes use of Winston Durand's backblaze gem
to access the B2 API behind the scenes.
Backblaze B2 Cloud Storage is similar to Amazon's AWS S3 Storage, but it has a few selling points:
- They run their own hardware (that's open-sourced, including the schematics, and drive reports)
- It's $0.005/GB/month vs S3's $0.030/GB/month
- You actually get a free GB of bandwidth a day, so it might be nice for personal projects.
Add this line to your application's Gemfile:
gem 'paperclip-backblaze', github: 'alextsui05/paperclip-backblaze'
And then execute:
$ bundle
You should be familiar with configuring Paperclip attachments for your model. If not, please start with the Paperclip documentation here.
Configuring Backblaze storage is very similar to configuring S3 storage.
Let's suppose we have a Note
model with an image
attachment that we would
like to be backed by Backblaze storage.
First, put your credentials and bucket name in a YML file.
# config/b2.yml
account_id: 123456789abc
application_key: 0123456789abcdef0123456789abcdef0123456789
bucket: my_b2_bucket_name
Then let Paperclip know about it. You can put it in your environment config:
# config/environments/production.rb
...
config.paperclip_defaults = {
storage: :backblaze,
b2_credentials: YAML.load(ERB.new(File.read("#{Rails.root}/config/b2.yml")).result).with_indifferent_access
}
Now just specify the attachment in the model, and it will use your backblaze configuration:
# app/models/note.rb
class Note < ApplicationRecord
has_attached_file :image
...
Currently, these are required options:
-
:storage
- This should be set to :backblaze in order to use this storage adapter. -
:b2_credentials
- Should be a Hash containing required fields listend in config/b2.yml.
This started as a proof of concept for a hobby project, so there's lots of room for improvement, and it would be great to have your help.
Bug reports and pull requests are welcome on GitHub at https://github.com/alextsui05/paperclip-backblaze. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
- CI setup and code style improvements
- Remove
:b2_bucket
option. It should now be specified in the credentials file with abucket
key. - Update example that doesn't pollute model with paperclip configuration
First release