Skip to content

Upload content endpoint (Legacy)

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

Not to be confused with Upload content endpoint (Non deprecated) this endpoint is no longer supported and is only present for backwards compatibility.

Description

This is the upload content endpoint, this endpoint will upload the content to the server. This endpoint will expect an 'id' argument for the id of the image, a 'type' argument for the type of the content (This MUST be either 'CHILL&CHAT_GIF' for a gif file type or 'CHILL&CHAT_IMG' for an image), a 'content' argument for the content to be uploaded and a 'user' argument for the user who sent the image. Furthermore, this endpoint will return a status of '401' on an invalid API key, '201' on success and '500' on an internal server error. The source code is located in /src/endpoints/uploadContent.ts.

Note

The content must be encoded in a base-64 format to be able to be uploaded to Chill&chat, please see https://en.wikipedia.org/wiki/Base64 for more information.

Example

post("http://<URL>/api/upload-content?key=<YOUR_API_KEY>", {
  id: "<ID>",
  user: "<USER>",
  type: "<TYPE>",
  content: "<CONTENT>",
})
  .then((res) => {
    console.log(res);
  })
  .catch((err) => {
    console.error(err);
  });

Encoding files in base-64

As the content argument for this endpoint requires that the image MUST be in a base-64 format, so here's how to encode it in node.js

import fs from "fs";

const encoded = fs.readFileSync("<FILE>", "base-64");

You can check https://nodejs.org/api/fs.html#fsreadfilesyncpath-options for more information on how to use it.

Clone this wiki locally