Spanish Total.js
English
Documentation For AI agents
Contents

REST API overview

The endpoints your apps call, how to send the token and what comes back.

.md GitHub
On this page

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 pathWhat 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 token query argument:
curl -F file=@sunset.png "https://files.example.com/upload/photos/?token=YOUR_TOKEN"
  • or in the x-token header:
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"}
FieldMeaning
idThe file ID in the storage.
nameThe file name.
sizeSize in bytes.
typeThe content type.
width, heightImage size in pixels; 0 for other files.
extThe file extension.
urlThe 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.

Made in Europe