b2 upload-file: Upload a Single File to B2
b2 upload-file uploads a single local file to a Backblaze B2 bucket under the object name you specify.
For a one-off artifact upload, upload-file is simpler than sync: it takes the bucket, the local path, and the destination file name. Note the B2 CLI v3+ renamed it to b2 file upload with the same idea.
What it does
b2 upload-file uploads one file to a bucket. The arguments are the bucket name, the local file path, and the B2 file name (the object key). It sets Content-Type automatically unless you override it, and can attach file info metadata.
Common usage
b2 authorize-account "$B2_KEY_ID" "$B2_APP_KEY"
b2 upload-file my-bucket ./build.tar.gz artifacts/build-${GITHUB_SHA}.tar.gz
# newer CLI (v3+) syntax
b2 file upload my-bucket ./build.tar.gz artifacts/build.tar.gzOptions
| Argument / flag | What it does |
|---|---|
| <bucket> | Target B2 bucket name |
| <localFile> | Local file to upload |
| <b2FileName> | Destination object key in the bucket |
| --contentType <type> | Override the auto-detected Content-Type |
| --info <k=v> | Attach custom file info metadata |
| --threads N | Parallel threads for a large-file upload |
In CI
Scope the B2 application key to just the target bucket and the writeFiles capability. For many files, b2 sync is better than looping upload-file because it parallelizes and skips unchanged files. Pin whether your runner has the v2 (upload-file) or v3 (file upload) CLI, since the subcommand name changed.
Common errors in CI
"ERROR: unable to authorize account" / "bad_auth_token" means a wrong or expired key; re-run authorize-account. "Bucket not found" is a wrong bucket name. "does not exist" on the local file is a missing artifact from an earlier step. On a v3 CLI, "invalid choice: 'upload-file'" means the subcommand was renamed to b2 file upload.