Appwrite Storage Meets Backblaze B2
Tags: opensource, appwrite, tutorial, cloud
Published: 2022-05-24 15:07:38

[Appwrite](https://appwrite.io/) is an open-source backend-as-a-service that abstracts all the complexity involved in building a modern application by providing you with a set of REST APIs for your core backend needs. Appwrite handles user authentication and authorization, real-time databases, cloud functions, webhooks, and much more! 

One of the core functionalities of Appwrite is [Appwrite Storage](https://appwrite.io/docs/storage). It permits you to upload, view, download, and query your project files. Appwrite Storage not only takes care of encryption, compression and antivirus scans, it’s also built on top of Appwrite’s flexible, yet simple permission system. Appwrite lets you store any files such as text documents, icons, images, videos, and more.

Recently, Appwrite introduced support for [Backblaze](https://www.backblaze.com/) as a storage adapter, allowing you to use Appwrite while not having to worry about your storage running out! 

## 💻 Backblaze B2 Setup

We’ll first need to set up our bucket and get some credentials before we can start using Backblaze storage with Appwrite.

1) Sign up for a [Backblaze account](https://secure.backblaze.com/user_signin.htm) and ensure  **B2 Cloud Storage service is enabled** under **Enabled Products** in your [account settings](https://secure.backblaze.com/user_signin.htm).

![backblaze account settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fzdj9ore8vsmfeokc2lc.png)


2) On the left navigation, you should see the products and their navigation display. Select the **Buckets** option from the navigation menu.

Navigating to **Buckets** will give you the option to create a bucket and configure it.


![Backblaze console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ql0bd9lgvskob254bop1.png)

<br>

![creating a bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9t5tghm09llw79aqt05.png)

3) Once you have your bucket created and configured, you can now go ahead and **create your application key and key IDs**. To create your application key and key ID navigate to **Account > App Keys** from the left navigation.

Scroll down past the master key section to create a new application key.(_Please note that you should **not** be creating a master key_)



![backblaze credentials](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uq6ws2r0263scetcdzw2.png)


This will give you your **keyID** and **applicationKey** which we will later use to connect Appwrite with Backblaze. 


![credentials popup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rhrndjwexotr1nrfzqp.png)



4) You will also need to get your region for the integration. You will be able to get your region details easily from your s3 endpoint which can be found on your **Buckets** page.
           
 
![bucket region](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dsudllssukaekisi04k6.png)     

The format of endpoints for the Backblaze S3 Compatible API looks as follows:

```
s3.<region>.backblazeb2.com
```
Hence, the region for the bucket `backblaze-demo` is `us-west-004`. Similarly, you can get your region from your bucket’s endpoint. 


With this we conclude the initial setup 💪 and now we will proceed to connect Backblaze B2 storage with Appwrite.  



## 🚀  Appwrite + Backblaze B2  

Before you start, make sure that you have your Appwrite instance up and running. Installation of Appwrite is as simple as running one command:
 
```
docker run -it --rm \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \
    --entrypoint="install" \
    appwrite/appwrite:latest
```

To learn more about the installation process, you can check out our [installation guide](https://appwrite.io/docs/installation).

We can now start configuring our `.env` file to integrate Backblaze B2 with Appwrite.

Here are some pointers before we start editing our `.env` file.

1) `_APP_STORAGE_DEVICE_BACKBLAZE_ACCESS_KEY` will hold your keyID from the Backblaze console.

2) `_APP_STORAGE_DEVICE_BACKBLAZE_SECRET` will hold your applicationKey from the Backblaze console.

As a first step, navigate to  `_APP_STORAGE_DEVICE` in the `.env` file and change it from `Local` (default) to `Backblaze`. This tells the Appwrite server to use Backblaze as the storage adapter and to expect Backblaze credentials in the other environment variables. 

You will also need to edit the following .env variables to get Appwrite connected with Backblaze.

```
_APP_STORAGE_DEVICE=Backblaze
_APP_STORAGE_DEVICE_BACKBLAZE_BUCKET=your bucket name
_APP_STORAGE_DEVICE_BACKBLAZE_REGION=region
_APP_STORAGE_DEVICE_BACKBLAZE_SECRET=your application key
_APP_STORAGE_DEVICE_BACKBLAZE_ACCESS_KEY=your key id
```








After editing your `.env` file, you will need to restart Appwrite. This can be easily done by running the following command.


```
docker-compose up -d
```

Once  Appwrite has restarted, create a new account and a new project. In the left menu, select ‘Storage’ and create a new bucket. Finally, upload a file into your bucket. You should see your uploaded files in the Backblaze console as well.


![files uploaded to the bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hw3dxmwhe55q151fyk39.png)







## 👨‍🎓 Conclusion

With the newly released provider system for Appwrite Storage service, you can now connect Appwrite with external storage providers instead of storing the files on your system. This prevents exhausting hard drive and bandwidth limits, as well as lets you use your favorite provider alongside Appwrite. And as you have seen in the tutorial above, you can easily connect Appwrite with Backblaze B2 in just a few steps!

If you have a project to share, need help, or simply want to become a part of the Appwrite community, I would love for you to join the official Appwrite [Discord server](https://appwrite.io/discord). I can’t wait to see what you build!

## 📚 Learn more

You can use the following resources to learn more and get help:

- 🚀 [Appwrite Github](https://github.com/appwrite)
- 📜 [Appwrite Docs](https://appwrite.io/docs)
- 💬 [Discord Community](https://appwrite.io/discord)