REST API overview
The endpoints your apps call, how to send the token and what comes back.
Your apps talk to OpenFiles over HTTP. The address of every endpoint starts with your OpenFiles address, for example https://files.example.com.
Endpoints
| Method and path | What it does |
|---|---|
POST /upload/{db}/ | Upload files as multipart/form-data. |
POST /files/{db}/ | The same as /upload/{db}/. |
POST /base64/{db}/ | Upload one file as Base64 in JSON. |
GET /files/{db}/{id}-{checksum}.{ext} | Open or download a file. Public, no token. |
{db} is the storage name, for example photos. The storage must exist; create it in Storages.
Send the token
Every upload needs an API token. Send it in one of two ways:
- as the
tokenquery argument:
curl -F file=@sunset.png "https://files.example.com/upload/photos/?token=YOUR_TOKEN"- or in the
x-tokenheader:
curl -H "x-token: YOUR_TOKEN" -F file=@sunset.png "https://files.example.com/upload/photos/"The header keeps the token out of server logs and browser history, so prefer it when your app can set headers.
What comes back
A successful upload answers 200 with JSON that describes the file:
{"id":"JapO3b1e961f","name":"sunset.png","size":2795,"type":"image/png","width":640,"height":480,"ext":"png","url":"/files/photos/JapO3b1e961f-pn.png"}| Field | Meaning |
|---|---|
id | The file ID in the storage. |
name | The file name. |
size | Size in bytes. |
type | The content type. |
width, height | Image size in pixels; 0 for other files. |
ext | The file extension. |
url | The link to the file. Relative, unless you add hostname=1. |
Save id and url in your app. Errors come back as a JSON array with an error text. See Errors and limits.
Cross-origin requests
The upload endpoints allow cross-origin requests, so a web page on another domain can upload directly. See Upload from a web page.