Workers API reference (2)·续
- An offset with an optional length.
- An optional offset with a length.
- A suffix.
offsetnumber- The byte to begin returning data from, inclusive.
lengthnumber- The number of bytes to return. If more bytes are requested than exist in the object, fewer bytes than this number may be returned.
suffixnumber- The number of bytes to return from the end of the file, starting from the last byte. If more bytes are requested than exist in the object, fewer bytes than this number may be returned.
R2PutOptions
onlyIfR2Conditional | Headers- Specifies that the object should only be stored given satisfaction of certain conditions in the
R2Conditional. Refer to Conditional operations. httpMetadataR2HTTPMetadata | Headersoptional- Various HTTP headers associated with the object. Refer to HTTP Metadata.
customMetadataRecord<string, string>optional- A map of custom, user-defined metadata that will be stored with the object.
Note
Only a single hashing algorithm can be specified at once.
md5ArrayBuffer | stringoptional- A md5 hash to use to check the received object's integrity.
sha1ArrayBuffer | stringoptional- A SHA-1 hash to use to check the received object's integrity.
sha256ArrayBuffer | stringoptional- A SHA-256 hash to use to check the received object's integrity.
sha384ArrayBuffer | stringoptional- A SHA-384 hash to use to check the received object's integrity.
sha512ArrayBuffer | stringoptional- A SHA-512 hash to use to check the received object's integrity.
storageClass'Standard' | 'InfrequentAccess'- Sets the storage class of the object if provided. Otherwise, the object will be stored in the default storage class associated with the bucket. Refer to Storage Classes.
ssecKeyArrayBuffer | string- Specifies a key to be used for SSE-C. Key must be 32 bytes in length, in the form of a hex-encoded string or an ArrayBuffer.
R2MultipartOptions
httpMetadataR2HTTPMetadata | Headersoptional- Various HTTP headers associated with the object. Refer to HTTP Metadata.
customMetadataRecord<string, string>optional- A map of custom, user-defined metadata that will be stored with the object.
storageClassstring- Sets the storage class of the object if provided. Otherwise, the object will be stored in the default storage class associated with the bucket. Refer to Storage Classes.
ssecKeyArrayBuffer | string- Specifies a key to be used for SSE-C. Key must be 32 bytes in length, in the form of a hex-encoded string or an ArrayBuffer.
R2ListOptions
limitnumberoptional- The number of results to return. Defaults to
1000, with a maximum of1000. - If
includeis set, you may receive fewer thanlimitresults in your response to accommodate metadata. prefixstringoptional- The prefix to match keys against. Keys will only be returned if they start with given prefix.
cursorstringoptional- An opaque token that indicates where to continue listing objects from. A cursor can be retrieved from a previous list operation.
delimiterstringoptional- The character to use when grouping keys.
includeArray<string>optional- Can include
httpMetadataand/orcustomMetadata. If included, items returned by the list will include the specified metadata. - Note that there is a limit on the total amount of data that a single
listoperation can return. If you request data, you may receive fewer thanlimitresults in your response to accommodate metadata. - The compatibility date must be set to
2022-08-04or later in your Wrangler file. If not, then ther2_list_honor_includecompatibility flag must be set. Otherwise it is treated asinclude: ['httpMetadata', 'customMetadata']regardless of what theincludeoption provided actually is.
This means applications must be careful to avoid comparing the amount of returned objects against your limit. Instead, use the truncated property to determine if the list request has more data to be returned.
const options = {
limit: 500,
include: ["customMetadata"],
};
const listed = await env.MY_BUCKET.list(options);
let truncated = listed.truncated;
let cursor = truncated ? listed.cursor : undefined;
// ❌ - if your limit can't fit into a single response or your
// bucket has less objects than the limit, it will get stuck here.
while (listed.objects.length < options.limit) {
// ...
}
// ✅ - use the truncated property to check if there are more
// objects to be returned
while (truncated) {
const next = await env.MY_BUCKET.list({
...options,
cursor: cursor,
});
listed.objects.push(...next.objects);
truncated = next.truncated;
cursor = next.cursor;
}
limit = 500
include = ["customMetadata"]
listed = await self.env.MY_BUCKET.list(limit=limit, include=include)
truncated = listed.truncated
cursor = listed.cursor if truncated else None
# ❌ - if your limit can't fit into a single response or your
# bucket has less objects than the limit, it will get stuck here.
while len(listed.objects) < limit:
...
# ✅ - use the truncated property to check if there are more
# objects to be returned
while truncated:
next_page = await self.env.MY_BUCKET.list(limit=limit, include=include, cursor=cursor)
listed.objects.extend(next_page.objects)
truncated = next_page.truncated
cursor = next_page.cursor
R2Objects
An object containing an R2Object array, returned by BUCKET_BINDING.list().
objectsArray<R2Object>- An array of objects matching the
listrequest. truncatedboolean- If true, indicates there are more results to be retrieved for the current
listrequest. cursorstringoptional- A token that can be passed to future
listcalls to resume listing from that point. Only present if truncated is true. delimitedPrefixesArray<string>- If a delimiter has been specified, contains all prefixes between the specified prefix and the next occurrence of the delimiter.
- For example, if no prefix is provided and the delimiter is '/',
foo/bar/bazwould returnfooas a delimited prefix. Iffoo/was passed as a prefix with the same structure and delimiter,foo/barwould be returned as a delimited prefix.
Conditional operations
You can pass an R2Conditional object to R2GetOptions and R2PutOptions. If the condition check for get() fails, the body will not be returned. This will make get() have lower latency.
If the condition check for put() fails, null will be returned instead of the R2Object.
etagMatchesstringoptional- Performs the operation if the object's etag matches the given string.
etagDoesNotMatchstringoptional- Performs the operation if the object's etag does not match the given string.
uploadedBeforeDateoptional- Performs the operation if the object was uploaded before the given date.
uploadedAfterDateoptional- Performs the operation if the object was uploaded after the given date.
Alternatively, you can pass a Headers object containing conditional headers to R2GetOptions and R2PutOptions. For information on these conditional headers, refer to the MDN docs on conditional requests ↗︎. All conditional headers aside from If-Range are supported.
For more specific information about conditional requests, refer to RFC 7232 ↗︎.
HTTP Metadata
Generally, these fields match the HTTP metadata passed when the object was created. They can be overridden when issuing GET requests, in which case, the given values will be echoed back in the response.
contentTypestringoptionalcontentLanguagestringoptionalcontentDispositionstringoptionalcontentEncodingstringoptionalcacheControlstringoptionalcacheExpiryDateoptional
Checksums
If a checksum was provided when using the put() binding, it will be available on the returned object under the checksums property. The MD5 checksum will be included by default for non-multipart objects.
md5ArrayBufferoptional- The MD5 checksum of the object.
sha1ArrayBufferoptional- The SHA-1 checksum of the object.
sha256ArrayBufferoptional- The SHA-256 checksum of the object.
sha384ArrayBufferoptional- The SHA-384 checksum of the object.
sha512ArrayBufferoptional- The SHA-512 checksum of the object.
R2UploadedPart
An R2UploadedPart object represents a part that has been uploaded. R2UploadedPart objects are returned from uploadPart operations and must be passed to completeMultipartUpload operations.
partNumbernumber- The number of the part.
etagstring- The
etagof the part.
Storage Class
The storage class where an R2Object is stored. The available storage classes are Standard and InfrequentAccess. Refer to Storage classes for more information.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/r2/api/workers/workers-api-reference/#page","headline":"Workers API reference","description":"Complete reference for the R2 in-Worker API, including bucket and object operations.","url":"https://developers.cloudflare.com/r2/api/workers/workers-api-reference/","inLanguage":"en","image":"https://developers.cloudflare.com/r2/api/workers/workers-api-reference/og.png?v=c3d660cabeabbae1","dateModified":"2026-07-31","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Define rate limits and interact with them directly from your Cloudflare Worker title: Rate Limiting image: https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/og.png?v=7e91c4cab8750517
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.
Docs