Skip to main content
Examples use the blob client from Creating the client.

put(file, options)

put() uploads one file and returns the new object.

Inputs

The object’s extension comes from filename, then the path’s basename or the File’s name. Bytes and a plain Blob have no name, so pass filename (for example "data.json") when uploading them.
In Node.js, a path that cannot be opened throws a plain Error (Cannot open file: <path>, with the original error in cause). In a browser, passing a path fails earlier, with the error from importing node:fs. Use a File from an <input type="file"> instead.

Options

See Object Post for the full server-side rules.

Result

Simple and multipart uploads

put() picks the upload flow from the file size: Every file must have at least 512 bytes; smaller files fail with FILE_TOO_SMALL. A rule or upload token max_size, or your storage quota, can lower the 10 GiB ceiling.

How a multipart upload runs

  1. The SDK starts the upload, and the server answers with its part limits (max_size, max_parts).
  2. The file is split into parts of min(max_size, max(16 MiB, ceil(size / max_parts))) bytes. A part is usually 16 MiB or more, but it is smaller when the server’s max_size is smaller.
  3. Parts are sent 6 at a time, the server’s limit for parts in flight. A failed part is retried within maxRetries.
  4. When every part arrived, the SDK completes the upload.
If a part fails for good, or completing fails, the SDK waits for the parts still in flight and then aborts the upload, so no part lands after the abort. The original error is thrown. There is no resume: call put() again.
A multipart upload does not check overwrite: false or checksum_sha256. It always replaces an existing object with the same name.
An account can have at most 32 open multipart uploads (shared with the S3 gateway); one more fails with TOO_MANY_OPEN_UPLOADS. Since parts go 6 at a time per account, run one large upload at a time.

Uploading from the browser

Never send the API key to a browser. Instead, your server mints a short-lived upload token and the browser uploads with it.
A client created with a token can only call put(), including multipart uploads. Any other method fails with 403 UPLOAD_TOKEN_NOT_ALLOWED.

uploadTokens.create(options)

The token pins every option it was minted with. It returns { token, expires_at, max_uses }. See Upload Tokens for the server-side rules.
uploadTokens.create() is a write and gets a single attempt: it is never retried.

Next steps

Objects

List, update, copy, move and delete objects.

Upload API reference

The REST endpoints behind put().