Mastodon
Mastodon ↗ is a popular fediverse ↗ software. This guide will explain how to configure R2 to be the object storage for a self hosted Mastodon instance, for either a new instance or an existing instance.
You can set up a self hosted Mastodon instance in multiple ways. Refer to the official documentation ↗ for more details. When you reach the Configuring your environment ↗ step in the Mastodon documentation after installation, refer to the procedures below for the next steps.
Different from the default hostname of your Mastodon instance, object storage for files requires a unique hostname. As an example, if you set up your Mastodon's hostname to be mastodon.example.com, you can use mastodon-files.example.com or files.example.com for accessing files. This means that when visiting your instance on mastodon.example.com, whenever there are media attached to a post such as an image or a video, the file will be served under the hostname determined at this step, such as mastodon-files.example.com.
-
In the Cloudflare dashboard, go to the R2 object storage page.
Go to Overview -
Select Create bucket.
-
Enter your bucket name and then select Create bucket. This name is internal when setting up your Mastodon instance and is not publicly accessible.
-
Once the bucket is created, navigate to the Settings tab of this bucket and copy the value of S3 API.
-
From the Settings tab, select Connect Domain and enter the hostname from step 1.
-
Navigate back to the R2's overview page and select Manage R2 API Tokens.
-
Select Create API token.
-
Name your token
Mastodonby selecting the pencil icon next to the API name and grant it the Edit permission. Select Create API Token to finalize token creation. -
Copy the values of Access Key ID and Secret Access Key.
While configuring your Mastodon instance based on the official configuration file ↗, replace the File storage section with the following details.