dwyl / dwyl/imgup

First tests - upload to B2 from the server seems ok with ExAws.S3

Open
#142 0 comments 7 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
108
Forks
20
Avg merge
21h 46m
Merged PRs (30d)
4

Description

You can set up a bucket in B2 quite simply. I did not do anything special. And it seems directly compatible with `ExAws.S3`🎉

Screenshot 2023-10-13 at 16 26 52

Screenshot 2023-10-13 at 16 27 42

Screenshot 2023-10-13 at 16 28 17

In place of the S3 config, I did:

```elixir
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.

```elixir
host = s3.
```

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).

```elixir
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()
```

Screenshot 2023-10-13 at 16 31 19

This uploads the file. The details are:

Screenshot 2023-10-13 at 16 24 13

and it serves the uploaded file at:

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.

Public bucket:

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.