Spanish Total.js
English
Documentation For AI agents
Contents

Upload files

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

.md GitHub
On this page
POST /upload/{db}/
POST /files/{db}/

Both paths do the same. Send the files as multipart/form-data, with the token 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

ArgumentMeaning
tokenThe API token, if you do not use the x-token header.
hostname=1Return an absolute url with the OpenFiles address.
idYour own ID for the uploaded file. Use letters and digits only.

One file

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

The answer is one object:

{"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:

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:

[{"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"}]
curl -H "x-token: YOUR_TOKEN" -F file=@sea.png "https://files.example.com/upload/photos/?id=homepagebanner&hostname=1"
{"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:

curl -H "x-token: YOUR_TOKEN" -F file=@forest.png -F file_id=forestthumb "https://files.example.com/upload/photos/"
{"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.

Any kind of file

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

{"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 for the failures.

Made in Europe