see their setup docs.
Install the packages @tinacms/auth
and next-tinacms-s3
using your favorite package manager. Mine is pnpm:
pnpm install @tinacms/auth next-tinacms-s3
In the tina/config.ts
, add (or replace if it already exists), the media
key as follows:
...
media: {
loadCustomStore: async () => {
const pack = await import('next-tinacms-s3');
return pack.TinaCloudS3MediaStore;
},
},
...
That’s it for the TinaCMS config! A painless change. We’ve still got some work to do, though, as it will error out if you try to browse the media library now.
We need a few key pieces of information from Backblaze B2. If you haven’t already, create an account and a B2 bucket that you’d like to use for your media library. Take note of a few pieces of information:
tinacms-media-library
).s3.us-west-000.backblazeb2.com
).keyID
and the applicationKey
for later.For this next step, let’s assume you are also deploying your application on Vercel. If not, TinaCMS docs have examples for other providers. Let’s set up the Vercel API route:
api
directory, and then next another directory, s3
, inside of it.s3
directory, create a file called [...media].mjs
import { createMediaHandler } from 'next-tinacms-s3/dist/handlers.js';
import tinaAuth from '@tinacms/auth';
const { isAuthorized } = tinaAuth;
export default createMediaHandler({
config: {
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY || '',
secretAccessKey: process.env.S3_SECRET_KEY || '',
},
region: ##INSERT-REGION-HERE##,
endpoint: ##INSERT-ENDPOINT-HERE##,
},
bucket: ##INSERT-BUCKET-NAME-HERE##,
authorized: async (req, _res) => {
try {
if (process.env.NODE_ENV == 'development') {
return true;
}
const user = await isAuthorized(req);
return user && user.verified;
} catch (e) {
console.error(e);
return false;
}
},
});
Most of this file replicates what TinaCMS gives us, but adds the endpoint
key under the config
object that allows us to use Backblaze B2 in place of Amazon S3.
When filling out the file above:
bucket
to the name of the bucket you created (example, tinacms-media-library
).endpoint
to the “Endpoint” value you recorded from your B2 bucket (example, s3.us-west-000.backblazeb2.com
).region
to the subdomain of your “Endpoint”. For example, if your endpoint is s3.us-west-000.backblazeb2.com
then set the region to us-west-000
.The above configuration pattern, specifically the endpoint
value, allow use of any other S3-compatible storage service, though I only tested with Backblaze B2.
Your project should be created in Vercel already (docs). We need to add two environment variables (environment variable docs):
S3_ACCESS_KEY
: set this to the keyID
you saved from the B2 API key setupS3_SECRET_KEY
: set this to the applicationKey
from the B2 API keyYour application should be ready to deploy now! Wait for Vercel to deploy, and then navigate to the media library in your TinaCMS instance. It should be able to read and upload files to Backblaze B2!