Press "Enter" to skip to content

How to use Backblaze as an Uppy destination

cross posted to https://community.transloadit.com/t/uploading-to-backblaze-b2-request-for-input/15110/3

I’m an Uppy user looking to save files to my Backblaze account. I’ve had some snags setting it up but I did get it working and thought I’d share here.

Uppy has S3 support https://uppy.io/docs/aws-s3/ and Backblaze has an S3 compatible API. Using this method, no custom code was necessary.

Uppy Companion is needed, along with settings for the following env variables.

COMPANION_AWS_ENDPOINT, COMPANION_AWS_BUCKET, COMPANION_AWS_KEY, COMPANION_AWS_SECRET.

On the js client side,

// full config redacted for brevity
import AwsS3Multipart from '@uppy/aws-s3-multipart';`
uppy.use(AwsS3Multipart, {
  limit: 4,
  companionUrl: '[redacted]',
})

I created a public Backblaze bucket. I’m not sure if the public setting is necessary, but I did run into an error when trying a private bucket and setting to public got me around the problem.

When I tried to upload using my uppy dashboard, I got an error regarding CORS.

Access to XMLHttpRequest at '[REDACTED FOR BREVITY]' from origin '[REDACTED FOR BREVITY]' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I think this was because Backblaze was not configured to allow s3_put from my website’s origin.

The fix for that was to set CORS via b2 command line interface. There are CORS settings in the Backblaze webUI, but it’s not enough to set it there. There is no way to set the allowedOperations, etc. in the web UI. Partial credit goes to https://www.reddit.com/r/backblaze/comments/m1fqni/comment/gqjjedq/?utm_source=share&utm_medium=web2x&context=3 for this solution.

b2-linux update-bucket --corsRules '[
    {
        "corsRuleName": "downloadFromAnyOriginWithUpload",
        "allowedOrigins": [
            "[MY_ORIGIN]"
        ],
        "allowedHeaders": [
            "*"
        ],
        "allowedOperations": [
            "s3_head",
            "s3_get",
            "s3_put"
        ],
        "exposeHeaders": [
            "ETag"
        ],
        "maxAgeSeconds": 3600
    }
]' [MY_BUCKET_NAME] allPublic

I think the above command needs to be run with a B2 App key that has the bypassGovernance capability, which for me was not the same app key used by my Uppy companion.

Looking for VOCALOID trading cards?

Check out Sakura Blossom Trading Post

Leave a Reply

Your email address will not be published.