Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/xxyoudeadpunkxx/cloudflare-r2-remote-mcp-worker/llms.txt

Use this file to discover all available pages before exploring further.

This page is the complete parameter and return-type reference for the two binary transfer tools: r2_upload_base64 and r2_download_base64. Both tools operate on raw bytes encoded as base64, making them suitable for any object regardless of content type. All transfers are bounded by MAX_TRANSFER_BYTES (default 1 MiB).

r2_upload_base64

Upload raw bytes to an R2 object by passing the content as a base64-encoded string. Optionally supply expectedEtag for a conditional write.

Parameters

key
string
required
Relative object key, scoped to R2_ROOT_PREFIX. Must not contain .., null bytes, or be an absolute path.
contentBase64
string
required
Base64-encoded bytes to store. The encoded string length must not exceed ceil(MAX_TRANSFER_BYTES / 3) * 4 characters, and the decoded byte length must not exceed MAX_TRANSFER_BYTES (default 1 MiB). Both checks are applied before the write.
contentType
string
MIME type to store with the object (e.g. image/png, application/pdf). When omitted, no Content-Type header is set.
customMetadata
object
Arbitrary string key-value pairs to attach as custom metadata.
expectedEtag
string
Conditional write guard. The write is rejected with etag_conflict if the current stored ETag does not match this value. Use "*" to require that the object already exists.

Returns

Returns the ObjectMetadata of the newly written object.
key
string
required
Relative key of the written object.
size
number
required
Stored size in bytes (decoded byte count).
contentType
string | null
required
MIME type stored with the object, or null if not set.
etag
string
required
ETag of the stored object.
lastModified
string | null
required
ISO 8601 UTC timestamp of the write.
customMetadata
object
required
Custom metadata key-value pairs attached to the object.

Error codes

CodeHTTP StatusMeaning
payload_too_large413Encoded string exceeds ceil(MAX_TRANSFER_BYTES / 3) * 4 characters, or decoded bytes exceed MAX_TRANSFER_BYTES.
etag_conflict409Conditional write failed — stored ETag did not match expectedEtag.
invalid_path400Key contains .., null bytes, or is otherwise invalid.

r2_download_base64

Download an R2 object and return its bytes as a base64-encoded string together with metadata. Works with any content type, including binary objects. The object size is checked against MAX_TRANSFER_BYTES before fetching.

Parameters

key
string
required
Relative object key, scoped to R2_ROOT_PREFIX.

Returns

key
string
required
Relative key of the downloaded object.
contentBase64
string
required
Base64-encoded bytes of the object body.
contentType
string | null
required
MIME type stored with the object, or null if not set.
etag
string
required
ETag of the stored object.
size
number
required
Object size in bytes (before base64 encoding).
lastModified
string | null
required
ISO 8601 UTC timestamp of the last write, or null if unavailable.
filename
string
required
Basename of the key (the final path segment after the last /). Useful for prompting a file-save dialog or naming a downloaded file.

Error codes

CodeHTTP StatusMeaning
object_not_found404No object exists at the given key.
payload_too_large413Object size exceeds MAX_TRANSFER_BYTES.

Size Limit Calculation

Both tools enforce MAX_TRANSFER_BYTES (default 1_048_576 bytes, configurable via the MAX_TRANSFER_BYTES environment variable).
MAX_TRANSFER_BYTES is expressed in decoded bytes, not base64 characters.

Upload size checks

r2_upload_base64 applies two sequential checks before writing to R2:
  1. Encoded length check — the base64 string length must not exceed ceil(MAX_TRANSFER_BYTES / 3) * 4 characters. This is a fast pre-check to avoid decoding large strings unnecessarily.
  2. Decoded byte check — the decoded Uint8Array byte length must not exceed MAX_TRANSFER_BYTES. This guards against padded or non-standard base64 strings that pass the length check but decode to oversized payloads.
Both checks throw payload_too_large (HTTP 413) on failure.

Download size check

r2_download_base64 calls r2_object_head first to read the stored size field and compares it against MAX_TRANSFER_BYTES. If the object is too large, the tool raises payload_too_large without fetching the body.

Base64 expansion factor

Base64 encoding expands binary data by approximately 4/3 (33%). A MAX_TRANSFER_BYTES value of 1 MiB (1,048,576 bytes) allows a maximum encoded string of approximately 1.33 MiB (1,398,104 characters).
max_base64_chars = ceil(MAX_TRANSFER_BYTES / 3) * 4

Error Codes

CodeHTTP StatusMeaning
payload_too_large413Object or payload exceeds MAX_TRANSFER_BYTES.
object_not_found404Object key not found in R2.
etag_conflict409Conditional write ETag mismatch (r2_upload_base64 only).
invalid_path400Key contains .., null bytes, or is otherwise invalid (r2_upload_base64 only).

Build docs developers (and LLMs) love