You can set up a bucket in B2 quite simply. I did not do anything special. And it seems directly compatible with ExAws.S3馃帀
In place of the S3 config, I did:
config :ex_aws, :s3,
debug_requests: true,
access_key_id: System.get_env("B2_KEY_ID"),
secret_access_key: System.get_env("B2_KEY_SECRET"),
host: s3.eu-central-003.backblazeb2.com,
bucket: up-image
The key point is to use host and not pass the region in the config. Then ExAws will automatically read this config for you.
host = s3.<b2_region><dns_suffix>
To use this, I have a browser tab opened serving a form with a file input (but you could curl -F ....). On submit, I POST the form to a controller. In the Phoenix code, you can use directly ExAws.S3.Upload and this can do multipart with zero efforts, the "standard" code (without XML parsing).
def handle_b2(conn, params) do
...
path
|> ExAws.S3.Upload.stream_file()
|> ExAws.S3.upload("up-image"), URI.encode(filename),
acl: :public_read,
content_type: mime,
content_disposition: "inline"
)
|> ExAws.request()
This uploads the file. The details are:
and it serves the uploaded file at: https://f003.backblazeb2.com/file/up-image/5ooil3d759vq8ng8hg0c.png
Seems slower than S3 but so far so good! 鉁岋笍
Next step: B2 -> Cloudfare CDN. For this, I need to create a domain on Cloudfare to cache the B2 bucket on the CDN.
https://www.backblaze.com/docs/cloud-storage-deliver-private-backblaze-b2-content-through-cloudflare-cdn
Public bucket: https://www.backblaze.com/docs/cloud-storage-deliver-public-backblaze-b2-content-through-cloudflare-cdn
You can set up a bucket in B2 quite simply. I did not do anything special. And it seems directly compatible with
ExAws.S3馃帀In place of the S3 config, I did:
The key point is to use
hostand not pass the region in the config. Then ExAws will automatically read this config for you.To use this, I have a browser tab opened serving a form with a file input (but you could
curl -F ....). On submit, I POST the form to a controller. In the Phoenix code, you can use directlyExAws.S3.Uploadand this can do multipart with zero efforts, the "standard" code (without XML parsing).This uploads the file. The details are:
and it serves the uploaded file at: https://f003.backblazeb2.com/file/up-image/5ooil3d759vq8ng8hg0c.png
Seems slower than S3 but so far so good! 鉁岋笍
Next step: B2 -> Cloudfare CDN. For this, I need to create a domain on Cloudfare to cache the B2 bucket on the CDN.
https://www.backblaze.com/docs/cloud-storage-deliver-private-backblaze-b2-content-through-cloudflare-cdn
Public bucket: https://www.backblaze.com/docs/cloud-storage-deliver-public-backblaze-b2-content-through-cloudflare-cdn