# Files

Upload, read, patch, watch and copy the files of a VM over its own HTTP API, with conditional writes and the limits that apply.

Source: https://slashinfra.com/docs/platform/files
Last modified: 2026-11-30T16:36:19.000Z

A VM serves its files at `https://<id>.slashinfra.dev`, its own API rather than the control API at `https://api.slashinfra.com`. You can upload, read, patch and watch them without a terminal; every request runs as your VM’s user, `user`, and the first one wakes a sleeping VM.

The samples use a VM named `files`. Create it once and keep the id:

```bash
si create --name files
```

Output

```text
6f1c0f0e8a
```

Set `VM` to the id in the reply and `SI_API_KEY` to a key from [API keys](https://app.slashinfra.com/keys):

```bash
export VM=6f1c0f0e8a
export SI_API_KEY=si_...
```

## Upload a file

`PUT` writes the request body to one file. It answers `201` for a new file and `204` for a replaced one, and the body of the answer is empty. The parent folder must exist, because the API does not create it. A new file gets mode `0644` and belongs to `user`; a replaced file keeps its mode and owner. The write is atomic, so a reader sees the old file or the new one.

### CLI

`si cp` writes one file. It prints nothing when the copy succeeds.

```bash
si cp notes.txt files:notes.txt
si exec files -- cat notes.txt
```

Output

```text
first line
second line
```

### curl

```bash
curl -sS -i -X PUT "https://$VM.slashinfra.dev/home/user/notes.txt" \
-H "Authorization: Bearer $SI_API_KEY" --data-binary @notes.txt
```

Output

```text
HTTP/2 201
content-type: text/plain; charset=utf-8
content-length: 0
...
```

### Python

```python
import os, requests

with open("notes.txt", "rb") as file:
res = requests.put(
f"https://{os.environ['VM']}.slashinfra.dev/home/user/notes.txt",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
data=file,
)
res.raise_for_status()
print(res.status_code)
```

Output

```text
201
```

### TypeScript

```ts
import { readFile } from 'node:fs/promises'

const body = await readFile('notes.txt')
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/home/user/notes.txt`, {
method: 'PUT',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
body,
})
if (!res.ok) throw new Error(await res.text())
console.log(res.status)
```

Output

```text
201
```

Send the same request again to replace the file; the answer is `204`. A `Content-Type` on the request is ignored, and the body is the file’s bytes. A body above 95 MiB answers `413`.

`If-None-Match: *` creates only a missing file and answers `412` when the path exists. `If-Match` with the `ETag` of a read replaces only that version and answers `412` when the file changed. Use the `ETag` from your own read; this stale value is refused:

```bash
curl -sS -i -X PUT "https://$VM.slashinfra.dev/home/user/notes.txt" \
-H "Authorization: Bearer $SI_API_KEY" -H 'If-Match: W/"1-1-1"' \
--data-binary @notes.txt
```

Output

```text
HTTP/2 412
...
```

## Read a file

`GET` returns the file’s bytes. `Content-Type` comes from the file extension; without a known extension the API sends `text/plain; charset=utf-8` for UTF-8 bytes and `application/octet-stream` otherwise. A `200` file reply carries a weak `ETag`, `Last-Modified` and `Accept-Ranges: bytes`.

### CLI

`si cp` writes the file to standard output with `-`; it does not show the headers.

```bash
si cp files:notes.txt -
```

Output

```text
first line
second line
```

### curl

```bash
curl -sS -i "https://$VM.slashinfra.dev/home/user/notes.txt" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
HTTP/2 200
content-type: text/plain; charset=utf-8
content-length: 23
etag: W/"73-23-1795959288819621052"
accept-ranges: bytes
...
first line
second line
```

### Python

```python
import os, requests

res = requests.get(
f"https://{os.environ['VM']}.slashinfra.dev/home/user/notes.txt",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.status_code, res.headers["ETag"])
print(res.text, end="")
```

Output

```text
200 W/"73-23-1795959288819621052"
first line
second line
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/home/user/notes.txt`, {
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(await res.text())
console.log(res.status, res.headers.get('ETag'))
process.stdout.write(await res.text())
```

Output

```text
200 W/"73-23-1795959288819621052"
first line
second line
```

`Range` returns one part with `206` and `Content-Range: bytes <first>-<last>/<size>`. Use `bytes=10-19`, `bytes=90-` for the rest, or `bytes=-5` for the last 5 bytes. Any other form returns the whole file, and a range on a folder is ignored.

```bash
curl -sS -i "https://$VM.slashinfra.dev/home/user/notes.txt" \
-H "Authorization: Bearer $SI_API_KEY" -H "Range: bytes=0-4"
```

Output

```text
HTTP/2 206
content-type: text/plain; charset=utf-8
content-length: 5
content-range: bytes 0-4/23
...
first
```

`If-None-Match` with the `ETag` answers `304` with no body when the file did not change. The answer still carries the `ETag` and `Last-Modified`.

```bash
ETAG=$(curl -sS -D - -o /dev/null "https://$VM.slashinfra.dev/home/user/notes.txt" \
-H "Authorization: Bearer $SI_API_KEY" | awk -F': ' 'tolower($1)=="etag"{print $2}' | tr -d '\r')
curl -sS -i "https://$VM.slashinfra.dev/home/user/notes.txt" \
-H "Authorization: Bearer $SI_API_KEY" -H "If-None-Match: $ETAG"
```

Output

```text
HTTP/2 304
etag: W/"73-23-1795959288819621052"
last-modified: Sun, 29 Nov 2026 13:34:48 GMT
...
```

## Read a folder

`GET` a folder returns a listing. Without `Accept`, it is the text form of `ls -la`: a `total` line, then permissions, owner, group, size, date and name. With `Accept: application/json`, it is an array of `{name, type, size, mode, mtime}`. The type is `file`, `dir`, `symlink` or `other`; `mode` is the Unix permission bits as a decimal number, and `mtime` is seconds since the Unix epoch. A folder’s `size` is its own metadata size, not the total of its contents.

The API has no tar response. To copy a tree, use `si cp -r`, which builds a tar on the VM and extracts it on the other side.

Create the `logs` folder with one file for the next sections. The command prints nothing.

```bash
si exec files -- sh -c 'mkdir -p logs && printf "started\n" > logs/job.log'
```

### CLI

```bash
si exec files -- ls -la logs
```

Output

```text
total 16
drwxr-xr-x 2 user user 4096 Nov 29 13:35 .
drwxr-xr-x 1 user user 4096 Nov 29 13:35 ..
-rw-r--r-- 1 user user    8 Nov 29 13:35 job.log
```

### curl

```bash
curl -sS "https://$VM.slashinfra.dev/home/user/logs/" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
total 16
drwxr-xr-x 2 user user 4096 Nov 29 13:35 .
drwxr-xr-x 1 user user 4096 Nov 29 13:35 ..
-rw-r--r-- 1 user user    8 Nov 29 13:35 job.log
```

### Python

```python
import os, requests

res = requests.get(
f"https://{os.environ['VM']}.slashinfra.dev/home/user/logs/",
headers={
"Authorization": f"Bearer {os.environ['SI_API_KEY']}",
"Accept": "application/json",
},
)
res.raise_for_status()
for entry in res.json():
print(entry["name"], entry["type"], entry["size"], entry["mode"])
```

Output

```text
job.log file 8 420
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/home/user/logs/`, {
headers: {
Authorization: `Bearer ${process.env.SI_API_KEY!}`,
Accept: 'application/json',
},
})
if (!res.ok) throw new Error(await res.text())
const entries = (await res.json()) as { name: string; type: string; size: number; mode: number }[]
for (const entry of entries) console.log(entry.name, entry.type, entry.size, entry.mode)
```

Output

```text
job.log file 8 420
```

A listing is capped at 16 MiB. A larger listing answers `413`.

## Watch a folder

`?watch` streams changes under a path as Server-Sent Events. A folder watches its whole tree, a file path watches that file, and changes to one path within 100 ms coalesce. Each event is `data: {"path":"/home/user/logs/job.log","kind":"modified"}`; `kind` is `created`, `modified`, `deleted` or `moved`. The stream stays open for up to one hour, the plan’s stream limit, and keeps the VM awake while it runs.

Run the watch in one terminal, then change a file in the folder from another.

### curl

```bash
curl -sS -N "https://$VM.slashinfra.dev/home/user/logs/?watch" \
-H "Authorization: Bearer $SI_API_KEY"
```

Output

```text
data: {"kind":"modified","path":"/home/user/logs/job.log"}

...
```

### Python

```python
import os, requests

with requests.get(
f"https://{os.environ['VM']}.slashinfra.dev/home/user/logs/",
params={"watch": ""},
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
stream=True,
timeout=10,
) as res:
res.raise_for_status()
for line in res.iter_lines(decode_unicode=True):
if line:
print(line)
break
```

Output

```text
data: {"kind":"modified","path":"/home/user/logs/job.log"}
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/home/user/logs/?watch`, {
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
signal: AbortSignal.timeout(10_000),
})
if (!res.ok || !res.body) throw new Error(await res.text())
const reader = res.body.getReader()
const decoder = new TextDecoder()
for (;;) {
const { done, value } = await reader.read()
if (done) break
const text = decoder.decode(value, { stream: true })
if (text.includes('data: ')) {
process.stdout.write(text)
await reader.cancel()
break
}
}
```

Output

```text
data: {"kind":"modified","path":"/home/user/logs/job.log"}
```

## Write at an offset

`PATCH` writes the body at a byte offset instead of replacing the file. The file must exist. `Content-Range` must be `bytes <start>-*/*`; an append starts at the current size. The API never leaves a hole: an offset past the end answers `416` and nothing is written. Concurrent `PATCH` and `PUT` requests in one folder do not interleave.

### CLI

The CLI has no offset write. Append with `si exec`:

```bash
si exec files -- sh -c 'printf "done\n" >> logs/job.log; cat logs/job.log'
```

Output

```text
started
done
```

### curl

```bash
curl -sS -i -X PATCH "https://$VM.slashinfra.dev/home/user/logs/job.log" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Range: bytes 8-*/*" \
--data-binary 'done
'
```

Output

```text
HTTP/2 204
...
```

### Python

```python
import os, requests

res = requests.patch(
f"https://{os.environ['VM']}.slashinfra.dev/home/user/logs/job.log",
headers={
"Authorization": f"Bearer {os.environ['SI_API_KEY']}",
"Content-Range": "bytes 8-*/*",
},
data=b"done\n",
)
res.raise_for_status()
print(res.status_code)
```

Output

```text
204
```

### TypeScript

```ts
const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/home/user/logs/job.log`, {
method: 'PATCH',
headers: {
Authorization: `Bearer ${process.env.SI_API_KEY!}`,
'Content-Range': 'bytes 8-*/*',
},
body: 'done\n',
})
if (!res.ok) throw new Error(await res.text())
console.log(res.status)
```

Output

```text
204
```

A body above 95 MiB answers `413`, and a write that would pass 95 MiB answers `413` too.

## Delete a file or folder

The VM API has no `DELETE`. A `DELETE` request answers `405 method_not_allowed` with `an SVM is deleted through the control plane, not on its own host`. Delete files and folders with `si exec`, which starts in `/home/user`.

> Caution
> 
> 
> 
> Deletes the files. `rm` cannot be undone. Download the files you need first.

```bash
si exec files -- rm -rf notes.txt logs
si exec files -- ls notes.txt logs
```

Output

```text
ls: cannot access 'notes.txt': No such file or directory
ls: cannot access 'logs': No such file or directory
```

To delete from HTTP, `POST` to `/bin/rm` with one `arg` for each argument; [Files and programs over HTTP](https://slashinfra.com/docs/build/files-and-programs) shows how `POST` runs a program.

## Copy between your laptop and the VM

`si cp` copies one file in either direction and prints nothing when it succeeds. The remote side is `<svm>:<path>`; a relative path is from `/home/user`, and `-` is standard input or output. `-r` copies a folder tree, and `--project` names a project other than `default`.

Upload one file:

```bash
si cp report.txt files:report.txt
si exec files -- cat report.txt
```

Output

```text
uploaded by si cp
```

Download one file:

```bash
si cp files:report.txt report-copy.txt
cat report-copy.txt
```

Output

```text
uploaded by si cp
```

The tree samples use a local `project` folder with `README.md` and `src/main.py`.

Copy a tree up:

```bash
si cp -r project files:project
si exec files -- find project -type f | sort
```

Output

```text
project/README.md
project/src/main.py
```

Copy a tree down:

```bash
si cp -r files:project project-copy
find project-copy -type f | sort
```

Output

```text
project-copy/README.md
project-copy/src/main.py
```

Name the destination file for one file; `-r` creates the destination folder. A tree copy is one tar archive, so a tree whose archive is above 95 MiB fails.

## Who can read and write files

A key must belong to the VM’s organization and include its project. The VM host checks the key and the project scope; it does not check a key action on a file request. A key that reaches the VM can read and write every file `user` can.

A grant is a token for one set of methods and paths. The gate checks the method and decoded path before the request wakes the VM, and the guest resolves paths beneath the grant root, so a symlink cannot leave it. Creating a grant takes `svm:write`. Send the token as `Authorization: Bearer <token>`. See [Grants](https://slashinfra.com/docs/platform/grants).

## Options

Every request body is raw bytes; the API accepts no JSON body. The path is in the URL, not a field.

### Upload

| Field | Type | Default | Allowed values | What it changes |
| --- | --- | --- | --- | --- |   
| `path` (path) | string | Required | At most 4096 bytes, no NUL byte; `/` is the root, and `.` and `..` resolve | The file to write. Its parent folder must exist. | 
| `If-None-Match` | string | Empty | `*` | Creates the file only when the path is free; an existing file answers `412`. | 
| `If-Match` | string | Empty | A weak `ETag`, or `*` | Replaces only that version; a changed or missing file answers `412`. `*` requires the file. | 
| `Content-Length` | integer | Computed from the body | 0 to 99614720 | The body size. A value above 95 MiB answers `413` before the body is read. |

### Read and watch

| Field | Type | Default | Allowed values | What it changes |
| --- | --- | --- | --- | --- |   
| `path` (path) | string | Required | At most 4096 bytes, no NUL byte; a trailing `/` names a folder | The file or folder to read. | 
| `Range` | string | Empty | `bytes=10-19`, `bytes=90-`, `bytes=-5` | One byte range. Any other form returns the whole file, and a range on a folder is ignored. | 
| `If-None-Match` | string | Empty | A weak `ETag`, or `*` | Answers `304` with no body when the file did not change. | 
| `Accept` | string | Text listing | `application/json`, or any other value for the text listing | A folder answers a JSON array instead of the text listing; an error becomes `{error, code}`. | 
| `watch` (query) | boolean | `false` | `?watch` in the query | Streams changes as Server-Sent Events instead of returning the path. |

### Write at an offset

| Field | Type | Default | Allowed values | What it changes |
| --- | --- | --- | --- | --- |   
| `path` (path) | string | Required | At most 4096 bytes, no NUL byte | The file to write. It must exist. | 
| `Content-Range` | string | Required | `bytes <start>-*/*` | The byte offset of the first body byte. A bounded range or a suffix answers `400`. | 
| `Content-Length` | integer | Computed from the body | 0 to 99614720 | The body size. |

## Errors

| Code | When | Fix |
| --- | --- | --- |   
| [`bad_request`](https://slashinfra.com/docs/reference/errors#bad_request) | The path has a NUL byte, or `Content-Range` has another form. | Remove the NUL byte; send `bytes <start>-*/*`. | 
| [`not_found`](https://slashinfra.com/docs/reference/errors#not_found) | The file, folder or parent folder does not exist, or the host is not a VM. | Check the path with `si exec files -- ls -la <dir>`, and `VM` with `si ls`. | 
| [`method_not_allowed`](https://slashinfra.com/docs/reference/errors#method_not_allowed) | The request uses `DELETE` or `HEAD`. | Use `GET`, `PUT`, `PATCH` or `POST`; delete with `si exec`. | 
| [`conflict`](https://slashinfra.com/docs/reference/errors#conflict) | `PUT` or `PATCH` names a folder. | Use a file path. | 
| [`precondition_failed`](https://slashinfra.com/docs/reference/errors#precondition_failed) | `If-None-Match` or `If-Match` did not hold. | Read the file again and use its new `ETag`; a create-only write needs a path that does not exist. | 
| [`payload_too_large`](https://slashinfra.com/docs/reference/errors#payload_too_large) | The body is above 95 MiB, or a listing is above 16 MiB. | Send less, split the file, read a part with `Range`, or copy with `si cp`. | 
| [`range_not_satisfiable`](https://slashinfra.com/docs/reference/errors#range_not_satisfiable) | A `Range` starts at or past the end, or a `PATCH` offset is past the end. | Read `Content-Range: bytes */<size>` and start at or before the end. | 
| [`timeout`](https://slashinfra.com/docs/reference/errors#timeout) | An upload or body stalled for more than 30 seconds. | Retry on a stable connection. | 
| [`file_read_failed`](https://slashinfra.com/docs/reference/errors#file_read_failed) | The VM could not read the file’s data. | Retry; if it repeats, copy the file with `si cp`. | 
| [`disk_full`](https://slashinfra.com/docs/reference/errors#disk_full) | The VM’s disk is full. | Remove files with `si exec files -- rm`. |

Errors that any request can return are in the [error catalog](https://slashinfra.com/docs/reference/errors).

## Permissions

| Operation | Who can | Key action |
| --- | --- | --- |   
| Read a file or folder | Any member with a key that includes the VM’s project | None | 
| Upload or replace a file | Any member with a key that includes the VM’s project | None | 
| Write at an offset | Any member with a key that includes the VM’s project | None | 
| Watch a file or folder | Any member with a key that includes the VM’s project | None | 
| Copy a file or tree | Any member with a key that includes the VM’s project | None | 
| Create a grant | Any member | `svm:write` |

## Limits

- A file upload or download is at most 95 MiB (99,614,720 bytes). A larger upload answers `413`; `si cp` refuses it before sending. 
- A folder listing is at most 16 MiB. A larger listing answers `413`. 
- A path is at most 4096 bytes and has no NUL byte. With a grant, the path and the grant scope share the 4096 bytes. 
- A new file gets mode `0644` and belongs to `user`, your VM’s user. A replaced file keeps its mode and owner. 
- A stalled transfer ends after 30 seconds. The transfer rate is 16 MiB/s per VM and 32 MiB/s per client address. 
- A file request wakes a sleeping VM. A watch keeps it awake until the stream ends, for up to one hour. See [Sleep and wake](https://slashinfra.com/docs/how/sleep-and-wake). 
- A single file write does not create parent folders. `si cp -r` creates the destination folder for a tree. 
- A tree copy is one tar archive, so a tree whose archive is above 95 MiB fails. Split it or use `si exec` with `tar`. 
- A file that `user` may not read or write answers `403`; change its mode with `si exec files -- chmod`. 
- The VM API has no `DELETE`; delete with `si exec` or [`POST /bin/rm`](https://slashinfra.com/docs/api-reference/svm#runProgram).

The full list is in [Limits](https://slashinfra.com/docs/reference/limits).

## Next

- [Files and programs over HTTP](https://slashinfra.com/docs/build/files-and-programs): run a program with the file you uploaded. 
- [Grants](https://slashinfra.com/docs/platform/grants): give another service one method and path without a key. 
- [Sleep and wake](https://slashinfra.com/docs/how/sleep-and-wake): what a file request wakes and how long a watch holds it.
