Files

2.1 KiB

R2 Patterns & Best Practices

Choose the access and delivery model, then fetch the implementation guide.

Task Current documentation
Stream object downloads or accept uploads through a Worker Use R2 from Workers
Add conditional reads/writes, range handling, checksums, or batch deletion Workers API reference
Upload large files with multipart state tracked by the client Multipart Worker and client example
Upload directly from a browser or share a temporary download Presigned URLs and CORS
Cache responses served by a Worker Cache API example
Deliver public objects through a custom domain or evaluate r2.dev Public buckets
Process object changes asynchronously Event notifications and Queues
Expire objects or transition storage classes Object lifecycles and storage classes

Authorize the caller for the selected object key and operation before exposing a Worker endpoint or issuing a presigned URL. A key-format check alone does not establish access rights. Set the intended expiry and signed request constraints for temporary access; configure browser CORS separately.

Keep private responses out of shared public caches. Choose cache keys and invalidation around the application's access model, and check R2 consistency and caching behavior when objects can change. For multipart uploads, plan for failed parts, completion, and cleanup using the linked guide.