Skip to main content

POST /uploads

Description

Uploads a binary file to the server and returns a json object with the file id, name, and url

The route handles the POST multipart request made to the /uploads path.

HTTP methodRoute
POST/uploads

Payload

The server needs to receive a binary file via the multipart/form-data request. As with all multipart MIME types, the request body should contain:

  • the Content-Disposition header that should be set to form-data
    • the name attribute with the upload value
    • filename - the original file name of the uploaded file
  • the Content-Type header - the type of the file data content

Only one file can be sent per request.

Example:

------WebKitFormBoundary1aDBIObTwl1A4Vpf
Content-Disposition: form-data; name="upload"; filename="Screenshot from 2022-11-11 12-35-01.png"
Content-Type: image/png

------WebKitFormBoundary1aDBIObTwl1A4Vpf--

Response

The route returns a json object with the file id, name, and url.

Example:


{
"id": 4,
"name": "cat.png",
"url": "https://server.com/uploads/4/cat.png"
}

The HTTP status code shows whether the request succeeds (response.status == 200) or fails (response.status == 500).


Related articles: Working with server