A client for the Backblaze B2 cloud storage service.
-
Add
b2_client
to your list of dependencies inmix.exs
:def deps do [{:b2_client, "~> 0.0.2"}] end
-
Ensure b2_client is started before your application:
def application do [applications: [:b2_client]] end
B2Client ships with two backends -- a HTTPoion-based backend meant for production and a in-memory temporary backend for testing. The default backend is the HTTPoison backend.
To change the backend you want to use in the current environment, simply add
the configuration in your config/XXX.exs
file:
config :b2_client, :backend, B2Client.Backend.Memory
To retrieve the current backend, use B2Client.backend
.
{:ok, auth} = B2Client.backend.authenticate("account ID", "application key")
{:ok, bucket} = B2Client.backend.get_bucket(auth, "my-bucket-name")
{:ok, file_contents} = B2Client.backend.download(auth, bucket, "file.txt")