Bindings
files
File storage, streamed in and out.
json
"bindings": { "UPLOADS": "files" }js
await env.UPLOADS.put("avatars/42.png", request.body, { type: "image/png" }) // {key, size, type, etag, uploaded}
const res = await env.UPLOADS.get("avatars/42.png") // a streamed Response, or null
return res ?? new Response("Not found", { status: 404 })
const meta = await env.UPLOADS.head("avatars/42.png") // {key, size, type, etag, uploaded} or null
await env.UPLOADS.delete("avatars/42.png") // true if it existed
const { files, cursor } = await env.UPLOADS.list({ prefix: "avatars/", limit: 100, cursor })put takes a string, ArrayBuffer, typed array, Blob or
ReadableStream. An upload is written to disk and synced before the key
points to it, so a reader sees the old file or the new one, never half.
Ranges and conditions
get(key, request) applies the request's Range and conditional headers:
pass the request, its headers or an object like {range: "bytes=0-1023"}.
It returns a 206 with that part, a 304 or a 416, ready to return, which
is what audio and video players need.
js
return (await env.UPLOADS.get(key, request)) ?? new Response(null, { status: 404 })Listing
list returns keys in order, up to 1000 per page; pass cursor back while it
is set.
Limits
Keys up to 1024 bytes; files up to 5 GB, within the service's disk quota.
From the API
http
GET /api/services/<name>/files/<BINDING>?prefix= → {files, cursor}
GET|PUT|DELETE /api/services/<name>/files/<BINDING>/file?key=<key>