Skip to content

Upload content endpoint

Alvin Cheng edited this page Jun 8, 2023 · 6 revisions

Description

This is the upload content endpoint, this endpoint will as the name suggests, upload a piece of content to the Chill&chat cloud service. This service makes it easy to upload custom chat images and profile images and use them from other places around the frontend app. This endpoint takes a couple of arguments, a 'key' parameter for the API key, an 'id' parameter for the id of the image, a 'user' parameter for the user it's assigned to, a 'type' parameter that is an enum that allows for 'CHILL&CHAT_IMG' and 'CHILL&CHAT_GIF' values for the respective types, and finally, a boolean 'useBinaryUpload' parameter for whether to use the old upload endpoint. Furthermore, this endpoint will return '401' on invalid API key, '500' on server error and '400' for invalid input. The source code is at /src/endpoints/uploadContent.ts. Anyways, here's an example!

Example

fetch(
  "http://<URL>/api/upload-content?key=<YOUR_API_KEY>&id=<ID>&user=<USER>&type=<TYPE>",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/octet-stream",
    },
    body: {
      /*<FILE>*/
    },
  }
)
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.error(err);
  });

Note

Please note that since we are uploading via binary, we need to set the Content-Type request header to application/octet-stream. Please see: https://developer.mozilla.org/en-US/docs/Glossary/Request_header for more information regarding this topic

Clone this wiki locally