Skip to content
Sveltia CMS
Esc
↑↓navigate↵open⌘Jpreview
On this page

Backblaze B2 Integration

Use Backblaze B2 as an external media storage provider in Sveltia CMS for cost-effective, S3-compatible object storage with zero egress fees.

Backblaze B2 is an S3-compatible object storage service with zero egress fees and low-cost storage. Sveltia CMS supports B2 as a media storage backend with direct browser-to-B2 uploads using AWS Signature Version 4 — no backend proxy is required.

Requirements

  • A Backblaze account with a B2 bucket created.
  • A B2 Application Key (see Credentials below).
  • CORS configuration via CLI (see CORS below) — the web console doesn’t support the required S3 operations.

CSP

If your site uses a Content Security Policy (CSP), you need to allow the B2 endpoint. See Content Security Policy below for details.

Setup

Credentials

B2 uses Application Keys for authentication. You can create keys via Backblaze Console > Account > Application Keys.

For production use, create a bucket-scoped Application Key with the following capabilities:

  • listFiles
  • readFiles
  • writeFiles
  • deleteFiles

Using the B2 CLI:

b2 key create --bucket my-bucket sveltia-cms listFiles,readFiles,writeFiles,deleteFiles

The resulting keyID goes in access_key_id in your config. The applicationKey (shown only once) is entered by users in the CMS UI when they access the media library for the first time — it is never stored in config.

Public Read Access

For asset previews and downloads to work, objects must be publicly readable. When creating a bucket, set its visibility to Public:

b2 bucket create my-bucket allPublic

With a public bucket, B2’s S3 endpoint serves objects anonymously, so no separate public_url configuration is needed — asset URLs use the virtual-hosted storage endpoint directly (https://{bucket}.s3.{region}.backblazeb2.com/{key}).

CORS

CORS is required because Sveltia CMS sends custom AWS Signature v4 headers that trigger a preflight request.

Setting CORS via B2 CLI

1. Install and authorize the B2 CLI (use a key with writeBuckets capability):

See the official documentation for installation instructions.

b2 account authorize <adminKeyId> <adminKey>

2. Set the CORS rule with S3 operations:

b2 bucket update --cors-rules '[{
  "corsRuleName": "sveltia-cms",
  "allowedOrigins": ["https://your-cms-domain.com"],
  "allowedOperations": ["s3_get", "s3_head", "s3_put", "s3_delete"],
  "allowedHeaders": ["*"],
  "exposeHeaders": ["ETag", "x-amz-request-id"],
  "maxAgeSeconds": 3600
}]' my-bucket allPublic

Replace https://your-cms-domain.com with your actual CMS origin and my-bucket with your bucket name. A wildcard * is allowed for allowedOrigins if you want to allow all origins.

See the official documentation for more details on CORS configuration.

3. Verify the configuration (optional):

b2 bucket get my-bucket

Required CORS Operations

The S3 operations Sveltia CMS requires are:

  • s3_get — for ListObjectsV2 (listing) and GetObject (preview/download)
  • s3_head — optional, for the unsigned HEAD requests the Asset Library sends to check whether files linked from entries still exist
  • s3_put — for PutObject (uploads and replacements) and CopyObject (renames)
  • s3_delete — for DeleteObject (deletions and renames)

Sveltia CMS uploads each file with a single PUT request, so s3_post (used for multipart uploads) isn’t needed.

Deleting and renaming files from the Asset Library require s3_delete and the wildcard allowedHeaders. If your existing rule lacks them, update it. Otherwise, the browser will block those requests during the preflight check.

B2 maps these native operations to the standard S3 HTTP methods (GET, HEAD, PUT, DELETE).

Configuration

Here’s an example configuration for Backblaze B2:

media_libraries:
  backblaze_b2:
    access_key_id: 0123456789abcdef0123456789ab
    bucket: my-bucket
    region: us-east-005
    prefix: cms-uploads/ # Optional
    public_url: https://cdn.example.com # Optional, only for private buckets
[media_libraries.backblaze_b2]
access_key_id = "0123456789abcdef0123456789ab"
bucket = "my-bucket"
region = "us-east-005"
prefix = "cms-uploads/"
public_url = "https://cdn.example.com"
{
  "media_libraries": {
    "backblaze_b2": {
      "access_key_id": "0123456789abcdef0123456789ab",
      "bucket": "my-bucket",
      "region": "us-east-005",
      "prefix": "cms-uploads/",
      "public_url": "https://cdn.example.com"
    }
  }
}
{
  media_libraries: {
    backblaze_b2: {
      access_key_id: '0123456789abcdef0123456789ab',
      bucket: 'my-bucket',
      region: 'us-east-005',
      prefix: 'cms-uploads/', // Optional
      public_url: 'https://cdn.example.com', // Optional
    },
  },
}

Configuration Properties

Property Required Description
access_key_id Yes B2 Application Key ID (keyID). Safe to store in config.
bucket Yes The B2 bucket name.
region Yes B2 region, e.g. us-west-001, us-east-005, eu-central-003. See B2 regions list.
prefix No Path prefix within the bucket, e.g. uploads/. A trailing slash is added if missing. In a File or Image field, it can contain template tags.
public_url No CDN or custom domain URL for asset previews. Only required for private buckets. Public buckets serve objects directly via the S3 endpoint.
label No Name shown for this storage in the CMS. Top-level only. See Custom Storage Name.

Public Buckets vs. Private Buckets

When a bucket is set to Public (allPublic), B2’s S3 endpoint serves objects anonymously without authentication. Asset URLs use the virtual-hosted storage endpoint:

https://{bucket}.s3.{region}.backblazeb2.com/{key}

No public_url configuration is needed — previews and downloads work automatically.

Private Buckets (Requires CDN)

For private buckets, you must configure a public_url pointing to a CDN or proxy that provides public access to the objects. B2’s S3 API always requires authentication, so direct storage URLs won’t work for previews in the CMS.

public_url: 'https://cdn.example.com'

Content Security Policy

API calls (list, upload) go to https://s3.{region}.backblazeb2.com. For public buckets, asset URLs use https://{bucket}.s3.{region}.backblazeb2.com:

connect-src https://s3.us-east-005.backblazeb2.com
            https://my-bucket.s3.us-east-005.backblazeb2.com;
img-src     https://my-bucket.s3.us-east-005.backblazeb2.com;

If using a private bucket with a CDN via public_url:

connect-src https://s3.us-east-005.backblazeb2.com
            https://cdn.example.com;
img-src     https://cdn.example.com;

Replace us-east-005 and my-bucket with your actual region and bucket name.

The asset host must be in connect-src because the Download and Copy buttons and the text preview in the Asset Library fetch the file from its public URL. For the same reason, a CDN must also send CORS headers that allow the CMS origin. Otherwise, downloads fail.

See the CSP documentation for more details.

B2-Specific Notes

No Per-Object ACLs

B2’s S3 API does not support the x-amz-acl header for per-object access control. Visibility is controlled at the bucket level (public or private). Sveltia CMS doesn’t send the header to B2, so uploads work correctly regardless of bucket visibility.

Region Endpoint

B2 uses a region-specific endpoint for the S3 API (https://s3.{region}.backblazeb2.com), and asset URLs use virtual-hosted-style addressing (https://{bucket}.s3.{region}.backblazeb2.com/{key}) for public buckets. This is handled automatically by Sveltia CMS.

Accessing the Storage

There are two ways to use Backblaze B2 in Sveltia CMS:

File and Image Fields

When editing content entries, users can use File and Image fields to upload and select media on Backblaze B2 directly within the entry editor. After entering the Application Key (secret) in the CMS UI when prompted, users can upload new media directly to B2 or select existing media from the bucket.

When uploading media, files will be stored in the B2 bucket with zero egress fees for downloads. You can also select existing media from your B2 storage.

Asset Library

Backblaze B2 also appears under External Locations in the Asset Library. There, users can browse, search, sort and filter the files in your bucket, and upload, rename, replace, download or delete them without leaving the CMS.

The files and folders are browsed folder by folder:

  • Subfolders are listed ahead of the files.
  • Uploads go to the folder being viewed.
  • Folders can be created, renamed and deleted.

Was this page helpful?