useR2Files hook handles uploads, listings, deletions, and signed URLs against the app’s R2 bucket. All operations route through the platform’s file gateway, so end users never touch raw R2 credentials. For patterns and worked examples, see the file uploads guide.
useR2Files(options?)
options is the R2Scope itself - pass { scope: 'self' } (or omit entirely; 'self' is the only valid scope). Every method that takes a file accepts either an R2FileInfo object from list() or a raw key string.
- Upload
- Upload (base64)
- List
- Delete
- Read / download
upload accepts a File (from <input type="file"> or a drag-drop event) or a Blob and an optional display name. Returns R2UploadResult - check success and read the key field.list() is an async function - call it and store the result in component state rather than reading a reactive array.
R2FileInfo
There is no
mimeType / contentType field on R2FileInfo. Capture the MIME type at upload time and store it in a sidecar collection if you need it later. See storing metadata.Scoping - R2Scope
scope: 'self') - the platform derives the bucket prefix from the request’s hostname. There is no per-user, per-room, or cross-app scope option exposed by useR2Files.
Display helpers
| Helper | Signature |
|---|---|
isImageFile(mimeType: string) | Returns true for image/* MIMEs |
formatFileSize(bytes: number) | Returns '1.2 MB', '456 KB', etc. |
Local dev limitation
See also
- File uploads guide - patterns and worked examples.
- Custom bindings - declare your own R2 bucket with custom permissions.