---
title: Upload files
project: OpenFiles
version: 1.0
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/openfiles/1-0/reference/upload/
updated: 2026-11-19T07:45:44.888Z
---

# Upload files

> POST /upload/{db}/: upload one or more files as multipart/form-data.

```text
POST /upload/{db}/
POST /files/{db}/
```

Both paths do the same. Send the files as `multipart/form-data`, with the [token](../rest-api/) in the `token` query argument or the `x-token` header. The token needs **Upload files** and the storage `{db}`. A request can be up to 100 MB.

## Query arguments

| Argument | Meaning |
|---|---|
| `token` | The API token, if you do not use the `x-token` header. |
| `hostname=1` | Return an absolute `url` with the OpenFiles address. |
| `id` | Your own ID for the uploaded file. Use letters and digits only. |

## One file

```bash
curl -H "x-token: YOUR_TOKEN" -F file=@sunset.png "https://files.example.com/upload/photos/"
```

The answer is one object:

```json
{"id":"JapO3b1e961f","name":"sunset.png","size":2795,"type":"image/png","width":640,"height":480,"ext":"png","url":"/files/photos/JapO3b1e961f-pn.png"}
```

## Several files

Send several file fields in one request:

```bash
curl -H "x-token: YOUR_TOKEN" -F file1=@sea.png -F file2=@forest.png "https://files.example.com/upload/photos/"
```

The answer is an array, one object per file:

```json
[{"id":"JapO3b1f960f","name":"sea.png","size":3577,"type":"image/png","width":800,"height":600,"ext":"png","url":"/files/photos/JapO3b1f960f-pn.png"},{"id":"JapO3b1g961f","name":"forest.png","size":1591,"type":"image/png","width":400,"height":300,"ext":"png","url":"/files/photos/JapO3b1g961f-pp.png"}]
```

## Absolute link and your own ID

```bash
curl -H "x-token: YOUR_TOKEN" -F file=@sea.png "https://files.example.com/upload/photos/?id=homepagebanner&hostname=1"
```

```json
{"id":"homepagebanner","name":"sea.png","size":3577,"type":"image/png","width":800,"height":600,"ext":"png","url":"https://files.example.com/files/photos/homepagebanner-14s.png"}
```

You can also set the ID per file with a form field named after the file field plus `_id`. Here the file field is `file`, so the ID field is `file_id`:

```bash
curl -H "x-token: YOUR_TOKEN" -F file=@forest.png -F file_id=forestthumb "https://files.example.com/upload/photos/"
```

```json
{"id":"forestthumb","name":"forest.png","size":1591,"type":"image/png","width":400,"height":300,"ext":"png","url":"/files/photos/forestthumb-xf.png"}
```

When you upload again with an ID that exists, the link serves the new file. See [Replace a file at the same link](../../recipes/replace-file/).

## Any kind of file

Any file type is accepted. For files that are not images, `width` and `height` are `0`:

```json
{"id":"JapO3b1h960f","name":"price-list.txt","size":38,"type":"text/plain","width":0,"height":0,"ext":"txt","url":"/files/photos/JapO3b1h960f-pp.txt"}
```

See [Errors and limits](../errors/) for the failures.
