Skip to content

Backblaze B2 (S3 Compatible)

Store files using Backblaze B2 with S3 compatible storage policy.

Configuration

Create a bucket in the Backblaze B2 console, then go to Application Keys and create a set of access keys with Read & Write permissions.

In Cloudreve, create an S3 Compatible storage policy and fill in the information according to the following rules:

  • For Bucket Name in the storage policy, enter the name of the bucket you just created;
  • For Endpoint in the storage policy, enter the Endpoint you obtained from the bucket list and add https:// at the beginning, for example https://s3.us-east-003.backblazeb2.com;
  • For Region in the storage policy, enter the region code observed in the Endpoint, for example us-east-003;
  • For Access credential in the storage policy, enter the keyID and applicationKey of the access key you just created. Make sure there are no extra spaces at the beginning or end;

CORS Policy

The bucket needs to be configured with a CORS policy before you can use the Cloudreve web interface to upload or browse files. Normally, you can let Cloudreve automatically configure the CORS policy when adding a storage policy.

If you need to configure it manually, download the B2 CLI tool according to the Backblaze documentation, and then execute ./b2-linux account authorize to log in to your account. (You can use the keyID and applicationKey created above)

Following the prompts, fill in the keyID and applicationKey, then execute the following command to modify the bucket's CORS configuration:

bash
./b2-linux bucket update <bucketName> --cors-rules '[
    {
        "allowedHeaders": [
            "authorization",
            "range",
            "content-type"
        ],
        "allowedOperations": [
            "s3_head",
            "s3_get",
            "s3_put",
            "s3_post",
            "s3_delete"
        ],
        "allowedOrigins": [
            "*"
        ],
        "corsRuleName": "s3DownloadFromAnyOriginWithUpload",
        "exposeHeaders": ["ETag"],
        "maxAgeSeconds": 3600
    }
]'

Reverse Proxy Private Bucket Download Requests

If you need to reverse proxy the download request of a private storage bucket, please enable the Use CDN for download traffic option in the storage policy settings and fill in your custom domain in the Download CDN field.

When configuring the reverse proxy, please note the following points:

  • The reverse proxy target is the B2 endpoint without the bucket name, for example, https://s3.us-west-004.backblazeb2.com;
  • The Host header needs to be overridden in the upstream request, for example, Host: s3.us-west-004.backblazeb2.com;
  • In the Cloudreve storage policy configuration, the Force path style option needs to be enabled;

As an example, the following is the Caddy configuration:

text
reverse_proxy {
    to https://s3.us-west-004.backblazeb2.com
    header_up Host s3.us-west-004.backblazeb2.com
}

FAQ

Upload error: Request failed: AxiosError: Network Error
  1. Check if the user can connect to your Backblaze B2 bucket Endpoint;
  2. Check if the CORS policy is correctly configured;
  3. Check Settings -> Filesystem -> Upload session TTL (seconds), its value should be less than 604800.
Transfer upload failed, error: Unable to parse response
  1. Expand the detailed error and check if the error message contains 413 Request Entity Too Large.

    If so, modify your Nginx reverse proxy configuration, set or increase the value of client_max_body_size, such as client_max_body_size 20000m;. This setting value should be larger than the size of the files being uploaded.

  2. Check if there is an external WAF firewall blocking the upload request.

Add CORS policy error: Failed to create cors: InvalidRequest: The bucket contains B2 Native CORS rules.

Go to the B2 bucket CORS policy settings, disable the built-in CORS policy, and then try to add the CORS policy in Cloudreve again.