File Storage
Store, stream and share files from your workers.
File Storage
Ploy File Storage is an object store for your workers: user uploads, images, PDFs, exports, and any other binary or text data. Files stream straight between your worker and storage, and signed URLs let browsers and other services download or upload files without going through your code.
Configuration
Add a file storage binding in your ploy.yaml:
kind: dynamic
build: pnpm build
out: dist
fs:
FILES: defaultThe key (FILES) is the binding name available in your worker's env. The value (default) is the file storage name. File storages belong to your organization: every binding that uses the same name, in any project, reads and writes the same files. Use different names, such as uploads_staging and uploads, to keep environments apart.
To cap the size of a single file, use the object form:
fs:
UPLOADS:
name: uploads
max_object_size: 10MBmax_object_size defaults to 100MB and can be raised to 5GB. Uploads above it fail, both through the binding and through signed URLs.
Run ploy types to generate TypeScript types:
import type { FileStorageBinding } from "@meetploy/types";
export interface Env {
FILES: FileStorageBinding;
}Basic Example
export default {
async fetch(request, env) {
const url = new URL(request.url);
const key = url.pathname.slice(1);
if (request.method === "PUT") {
// Streams the request body into storage without buffering it
const object = await env.FILES.put(key, request.body, {
contentType: request.headers.get("Content-Type") ?? undefined,
size: Number(request.headers.get("Content-Length")),
});
return Response.json(object);
}
const file = await env.FILES.get(key);
if (!file) {
return new Response("Not Found", { status: 404 });
}
const headers = new Headers({ ETag: file.httpEtag });
file.writeHttpMetadata(headers);
return new Response(file.body, { headers });
},
} satisfies Ploy;API Methods
put(key, value, options?) - Store a File
Stores a file, replacing any file at the same key, and returns its metadata. value can be a string, ArrayBuffer, typed array, Blob, ReadableStream, or null.
await env.FILES.put("reports/2025.pdf", pdfBytes, {
contentType: "application/pdf",
cacheControl: "private, max-age=3600",
customMetadata: { userId: "u_123" },
});| Option | Description |
|---|---|
contentType | MIME type. Defaults to the Blob's type or application/octet-stream. |
cacheControl | Stored with the file and returned by writeHttpMetadata(). Signed URL downloads cap it to the URL's lifetime. |
contentDisposition | Stored with the file and returned by writeHttpMetadata(). |
customMetadata | Up to 2KB of string pairs stored with the file. |
size | Length of a ReadableStream. With it the upload streams in one request; without it, it is sent in parts. |
onlyIf | { etagDoesNotMatch: "*" } stores the file only if the key is free; put() returns null otherwise. |
Keys are up to 1024 bytes. They cannot start or end with /, contain //, . or .. segments, backslashes, or control characters.
get(key, options?) - Retrieve a File
Returns the file or null. body is a ReadableStream; pass it to new Response() to stream the file to the client, or read it with text(), json(), arrayBuffer(), bytes() or blob().
const file = await env.FILES.get("config/app.json");
if (file) {
console.log(file.contentType, file.size, file.etag, file.uploaded);
const config = await file.json();
}
// Read part of a file
const header = await env.FILES.get("video.mp4", {
range: { offset: 0, length: 1024 },
});
// Skip the download when the client already has this version
const fresh = await env.FILES.get("logo.png", {
onlyIf: { etagDoesNotMatch: cachedEtag },
});With onlyIf, a failed condition returns the file's metadata without a body.
head(key) - Read Metadata
Returns the same metadata as get(), without the contents, or null.
const info = await env.FILES.head("reports/2025.pdf");
// { key, size, etag, uploaded, contentType, httpMetadata, customMetadata, ... }delete(keys) - Delete Files
Deletes one key or up to 1000 at once. Missing keys are ignored.
await env.FILES.delete("reports/2025.pdf");
await env.FILES.delete(["tmp/a", "tmp/b"]);list(options?) - List Files
Lists files in key order, up to 1000 per call. When truncated is true, pass cursor to get the next page. List results don't include content types; use head() for those.
let cursor: string | undefined;
do {
const page = await env.FILES.list({ prefix: "uploads/u_123/", cursor });
for (const object of page.objects) {
console.log(object.key, object.size, object.uploaded);
}
cursor = page.truncated ? page.cursor : undefined;
} while (cursor);
// Group keys into folders
const { objects, delimitedPrefixes } = await env.FILES.list({
prefix: "images/",
delimiter: "/",
});
// delimitedPrefixes: ["images/avatars/", "images/banners/"]createSignedUrl(key, options?) - Share a File
Returns a URL that downloads (GET) or uploads (PUT) one file directly, without passing through your worker. Anyone with the URL can use it until it expires.
// A download link valid for one hour
const { url } = await env.FILES.createSignedUrl("reports/2025.pdf", {
expiresIn: 3600,
filename: "Annual report.pdf",
});
// An upload URL the browser sends the file to
const upload = await env.FILES.createSignedUrl(`uploads/${userId}/${id}.png`, {
method: "PUT",
contentType: "image/png",
maxSize: 5 * 1024 * 1024,
expiresIn: 600,
});
// { url, method: "PUT", expiresAt, headers: { "Content-Type": "image/png" } }| Option | Description |
|---|---|
method | GET (default) or PUT. |
expiresIn | Seconds until the URL expires: up to 7 days for GET (default 1 hour), up to 1 hour for PUT (default 15 minutes). |
contentDisposition | GET: attachment (default) downloads the file; inline lets the browser display it. |
filename | GET: the download's file name. Defaults to the key's last segment. |
contentType | PUT: the Content-Type the upload must send. |
maxSize | PUT: the largest upload accepted, capped by the binding's max_object_size. |
overwrite | PUT: allow the upload to replace an existing file. By default it can only create the file. |
Expiry times are rounded up to the next five minutes, so creating a URL for the same file twice returns the same URL and browsers can reuse their cached copy.
Signed URLs
Direct browser uploads
Create a PUT URL on the server after checking that the user may upload, then send the file from the browser:
const { url, headers } = await fetch("/api/uploads", { method: "POST" }).then(
(response) => response.json(),
);
await fetch(url, { method: "PUT", headers, body: file });The upload must send a Content-Length within maxSize and, when the URL was created with contentType, exactly that Content-Type. Otherwise it fails with 413 or 415. Signed URLs answer CORS preflights for any origin, so uploads work from your app's domain and from local development.
Security
Signed URLs are served from a separate files domain when your Ploy instance has one, and otherwise under /_ploy/fs/ on the domain of the app that created them. A URL only works on that domain, and /_ploy/fs/ on an app's domain only serves files of the app's own organization.
Every download is sent with X-Content-Type-Options: nosniff and a sandboxing Content Security Policy, and as an attachment unless the URL was created with contentDisposition: "inline". Browsers can only display PDFs without the sandbox, so inline PDFs are shown from the files domain and downloaded as attachments elsewhere. An uploaded HTML or SVG file can't run scripts on your site.
A signed URL is bound to one file, one method, its expiry, and for uploads its size and type. Changing any part of it invalidates it. Uploads are also guarded against misuse:
- An upload URL creates the file once. Using it again fails with
412, so a client can't replace a file after your server checked it. Passoverwrite: trueto allow replacing. - Without
contentType, an upload URL rejects HTML, XHTML, SVG and XML files with415. Sign the URL for that exact type to accept them.
To revoke every outstanding URL of a file storage, for example after a link leaked, click Revoke signed URLs on its page in the dashboard (owners and admins). Old URLs stop working within 30 seconds, and files stay in place. Links you create after revoking work right away. Deleting a file storage also invalidates its URLs, even if a new one is created with the same name.
Downloads are sent with Cache-Control: private and a max age of at most an hour, never longer than the URL stays valid, whatever cacheControl the file was stored with. They support Range requests and answer If-None-Match with 304 Not Modified.
Limits
| Limit | Value |
|---|---|
| File size | 100MB by default, up to 5GB per binding |
| Key length | 1024 bytes |
| Custom metadata | 2KB |
Keys per list() or delete() | 1000 |
| Signed download URL lifetime | 7 days |
| Signed upload URL lifetime | 1 hour |
Upgrading from string bodies
get() used to return body as a string. It now returns a stream, like a Response. Deployments made before this change keep receiving strings until you redeploy, so a running app isn't affected. Before redeploying, replace any string use of file.body with await file.text(). new Response(file.body) works as before.
Migrating from Supabase Storage
| Supabase Storage | Ploy File Storage |
|---|---|
| Bucket | A file storage binding: fs: { FILES: uploads } |
storage.from(bucket).upload(path, file) | env.FILES.put(path, file, { contentType }) |
storage.from(bucket).download(path) | env.FILES.get(path) |
storage.from(bucket).remove([paths]) | env.FILES.delete([paths]) |
storage.from(bucket).list(folder) | env.FILES.list({ prefix: folder, delimiter: "/" }) |
createSignedUrl(path, expiresIn) | env.FILES.createSignedUrl(path, { expiresIn }) |
createSignedUploadUrl(path) | env.FILES.createSignedUrl(path, { method: "PUT", contentType, maxSize }) |
Public bucket and getPublicUrl(path) | A signed GET URL with a long expiry (up to 7 days), or a route in your worker that streams get() |
| Storage RLS policies | Checks in your server code before get(), put() or createSignedUrl() |
fileSizeLimit and allowedMimeTypes on a bucket | max_object_size in ploy.yaml, and maxSize/contentType on upload URLs |
Differences to plan for:
- No public buckets. Every file is private. Hand out signed URLs, or serve files from a route in your worker, where you can add your own caching headers.
- No row-level security. Resolve the user in your server code and decide there which keys they may read or write, for example by putting their ID in the key.
- Copying existing files: download each object from Supabase and
put()it under the same path. Keep paths stable if your database stores them.
Differences from State
| File Storage | State | |
|---|---|---|
| Designed for | Files of any type and size | Durable key-value data |
| Metadata | Content type, cache control, custom metadata, ETag | Optional metadata |
| Listing | list() with prefix, delimiter and cursor | list() with KV-style cursor |
| Sharing | Signed URLs for direct download and upload | None |
| TTL | None (persists until deleted) | Optional expiration TTL |
Next Steps
- Next.js file storage guide - Upload and serve files from a Next.js app
- State - Add durable key-value storage
- Databases - Add persistent SQLite databases
- Workers - Learn about Ploy workers
How is this guide?
Last updated on