Created
March 29, 2018 18:27
-
-
Save Paxa/d13da6d33e76f748cb40de576f03695a to your computer and use it in GitHub Desktop.
fog-backblaze example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'fog-core', '>2.0' | |
gem 'fog-backblaze' | |
require 'fog/core' | |
require 'fog/backblaze' | |
TEST_BUCKET = ENV['B2_BUCKET'] || 'fog-demo-1505931432' | |
if !ENV['B2_ACCOUNT_ID'] || ENV['B2_ACCOUNT_ID'] == "" | |
puts "Missing env B2_ACCOUNT_ID" | |
exit 1 | |
end | |
if !ENV['B2_ACCOUNT_TOKEN'] || ENV['B2_ACCOUNT_TOKEN'] == "" | |
puts "Missing env B2_ACCOUNT_TOKEN" | |
exit 1 | |
end | |
for_settings = { | |
provider: 'backblaze', | |
b2_account_id: ENV['B2_ACCOUNT_ID'], | |
b2_account_token: ENV['B2_ACCOUNT_TOKEN'] | |
} | |
connection = Fog::Storage.new(for_settings) | |
# First, a place to contain the glorious details | |
directory = connection.directories.create( | |
key: "fog-demo-#{Time.now.to_i}", # globally unique name | |
public: true | |
) | |
at_exit do | |
directory.files.each do |file| | |
puts "removing file #{file.key}" | |
p file.destroy | |
end | |
puts "removing a bucket #{directory.key}" | |
p directory.destroy | |
end | |
# list directories | |
p connection.directories | |
# upload that resume | |
file = directory.files.create( | |
key: 'Gemfile.lock', | |
body: File.open("./Gemfile.lock"), | |
public: true | |
) | |
# list files | |
p directory.files | |
# get file | |
p directory.files.get('Gemfile.lock') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment