I've created a API only Phoenix framework boilerplate. Check it out on github factsfinder/phoenix_api

Hello everyone, I’ve created an API only phoenix boilerplate. You can check on github here: https://github.com/factsfinder/pheonix_api

I’ve come across elixir and Pheonix only an year ago. Decided to make a boilerplate out of my current side project’s phoenix api.

Hopefully it will be useful or save time of atleast one of ya.

Thanks and keep drinking elixir everyday :slight_smile:

4 Likes

I notice you’re using Backblaze instead of S3. Something I also wanted to look into, can you describe that process a bit more? Is it doing a direct upload to backblaze? Or does the file pass through the server?

1 Like

Sure. Using Backblaze cause b2 cloud storage is s3 compatible https://www.backblaze.com/b2/cloud-storage.html and 4 times cheaper than aws s3.

I’m not using any other server to upload files to backblaze. All the implementation is right there in the repo.

So I’m just using a combination of these libraries:

arc => https://github.com/stavro/arc
arc_ecto => https://github.com/stavro/arc_ecto

ex_aws => https://github.com/ex-aws/ex_aws
ex_aws_s3 => https://github.com/ex-aws/ex_aws_s3

Please note that in case of ex_aws and ex_aws_s3 I’m using forked versions that I made changes to support backblaze.
Here are forked ones that are being used right now.


Pls check the lib => api => uploads => image.exs file to get a much better idea.

Let me know if you have any questions.

1 Like

Does ex_aws support backblaze now? Or should I use your fork still?

It doesn’t appear so @maz, the ex_aws and ex_aws_s3 libraries only have support for the official AWS regions.

I ended up following the excellent work @factsfinder did in his original fork, just done to the latest main branch of each of these repos. If it helps for your own reference, here’s the forks:

I use them in a Phoenix application by updating mix.exs to include:

{:ex_aws, git: "https://github.com/chrislaskey/ex_aws.git", branch: "main", override: true},
{:ex_aws_s3, git: "https://github.com/chrislaskey/ex_aws_s3.git", branch: "main"},
{:hackney, "~> 1.18"}

And in config/runtime.exs:

config :ex_aws,
  access_key_id: [System.get_env("AWS_ACCESS_KEY_ID"), :instance_role],
  secret_access_key: [System.get_env("AWS_SECRET_ACCESS_KEY"), :instance_role],
  region: System.get_env("BACKBLAZE_B2_REGION")

Where the value of BACKBLAZE_B2_REGION in my case is "us-west-001".

And as a quick sanity check things are working, I use this command to from the REPL to verify a file download from the existing B2 bucket is working:

ExAws.request(ExAws.S3.download_file("nameofmyb2bucket", "hello.txt", "world.txt"))

Note: at the time of writing, I only updated my forks to support "us-west-001" and "us-west-002". If you need other Backblaze B2 regions, you’ll need to add them following the same pattern.

2 Likes

Looks like it is actually possible.

I got a presigned url from backblaze using above ex_aws_s3 config