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 the file "<path>". Check that the path exists and that this process can read it., with the original error in cause). Outside Node.js, any path throws a plain Error (File paths can only be uploaded in Node.js. Pass a Blob, a File or bytes instead.). In a browser, 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
- The SDK starts the upload, and the server answers with its part limits (
max_size,max_parts). - 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 (the service accepts up to 32 MiB), but it is smaller when the server’smax_sizeis smaller. - Parts are sent 6 at a time, the server’s limit for parts in flight. A failed part is retried within
maxRetries. - When every part arrived, the SDK completes the upload.
put() again. After a 503 STORAGE_UNAVAILABLE, wait about 10 seconds first (see Storage outages).
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.Overwrite check on multipart uploads
A multipart upload respectsoverwrite: false. Right after it starts the upload, the SDK checks the name with info():
- If the object exists, the SDK aborts the upload before sending any part and throws
409 OBJECT_ALREADY_EXISTS. - If the check gets a
429, the SDK aborts the upload before sending any part and throws that429. - Any other failure of the check, such as a missing
blob:read, a404or a network error, lets the upload go on.
blob:read scope. The service checks the name again when the upload completes, since the object may have appeared in the meantime. On that 409, the SDK aborts the upload, which frees one of the 32 open-upload slots and discards the parts.
There is no check with private: true or security_hash: true, because the name gets a random hash and cannot be taken. There is none with an upload token either: the service ignores overwrite for token uploads, and the token decides whether its upload can replace an object.
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.- Server
- Browser
put(), including multipart uploads. Any other method fails with 403 UPLOAD_TOKEN_NOT_ALLOWED.
The SDK calls https://blob.squarecloud.app with the global fetch, so a page with a Content Security Policy must allow that origin in connect-src.
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.
Minting fails with 403 PREFIX_NOT_ALLOWED when a key restricted to prefixes asks for a prefix outside them, 403 PERMISSION_DENIED when the credential cannot mint tokens, 403 UPGRADE_REQUIRED for an option your plan lacks, and 401 PERMISSION_DENIED when the account has no active plan.
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().

