# Files

Store uploads, images, PDFs and generated reports up to 25 MB, and serve them from your functions.

```js
import { file } from 'wisp';

await file.write('reports/2026-11.csv', csvText);           // content type from the extension
const info = await file.stat('reports/2026-11.csv');         // { path, size, contentType, updatedAt }
const bytes = await file.read('uploads/42/photo.jpg');       // Buffer, or null
```

```python
from wisp import file

file.write("reports/2026-11.csv", csv_text)
info = file.stat("reports/2026-11.csv")
data = file.read("uploads/42/photo.jpg")  # bytes, or None
```

## Methods

| Method | Returns |
| --- | --- |
| `write(path, data, { contentType })` | `{ path, size, contentType, updatedAt }`. Replaces an existing file. |
| `read(path)` | Bytes, or `null` / `None` |
| `readText(path)` (Python `read_text`) | A string, or `null` / `None` |
| `stat(path)` | Metadata without downloading, or `null` / `None` |
| `delete(path)` | — |
| `list({ prefix, limit, cursor })` | `{ items: [{ path, size, updatedAt }], cursor }` |

Full signatures: [file reference](/api/sdk-file).

## Paths

Use folder-like paths such as `uploads/<id>/photo.jpg`: no leading slash, no `..`, up to 1,024 bytes. The console groups files by their top-level folder.

## Serve a file

```js
export async function handler(req) {
  const id = req.subpath.slice(1);
  const meta = await file.stat(`images/${id}.png`);
  if (!meta) return { status: 404, body: { error: 'Not found' } };
  return { status: 200, headers: { 'content-type': meta.contentType }, body: await file.read(meta.path) };
}
```

Responses are limited to about 6 MB. Combine with [edge caching](/edge-caching) for files that don't change often.

## Accept an upload

Send the file as the raw request body:

```bash
curl -X POST "https://my-api.fn.wispfn.com/upload?name=photo.jpg" \
  -H "content-type: image/jpeg" --data-binary @photo.jpg
```

```js
export async function handler(req) {
  const data = req.isBase64Encoded ? Buffer.from(req.rawBody, 'base64') : Buffer.from(req.rawBody);
  const saved = await file.write(`uploads/${crypto.randomUUID()}/${req.query.name}`, data);
  return { status: 201, body: saved };
}
```

## Limits

- Files up to 25 MB.
- Request bodies up to 6 MB — split bigger uploads or upload them elsewhere.
- Keep an index in [key-value](/key-value) or a [table](/tables) when you need to find files by something other than their path.
