Files

All available operations for managing files


Upload a file #

This endpoint uploads a file to Cord's file storage. The file can then be used in other Cord APIs, such as as a message attachment.

Certain types of files, such as executable code, cannot be uploaded. Trying to do so will generate an error.

Files that are uploaded but never attached to a message will eventually be garbage collected.

HTTP Request #

HTTP:
POST https://api.cord.com/v1/files
cURL:
curl "https://api.cord.com/v1/files" \
  -X POST \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
CLI:
# you can install @cord-sdk/cli for a simpler experience
cord file upload
POST https://api.cord.com/v1/files
Copy

Request Body #

Listed below are the fields of the request body to be added as part of the HTTP POST request.

Note: Unlike most of Cord's REST APIs, this request must be encoded as multipart/form-data.


file
required
file
The contents of the file.

ownerID
required
string
The ID of the user that owns the file. Files can only be attached to messages authored by their owner.

name
optional
string
The name of the file. This will be shown to the user when attached to a message and will be the file's name if it's downloaded. If not supplied, it will be taken from the filename of the file parameter.

Response #

If successful, the response will be:

JSON:
{
  "success": true,
  "message": "✅ File created.",
  "fileID": "12345678-90ab-cdef-1234-567890abcdef"
}
{
  "success": true,
  "message": "✅ File created.",
  "fileID": "12345678-90ab-cdef-1234-567890abcdef"
}
Copy

Example Request #

Node:

              import path from 'path';
              import mime from 'mime';
              import { FormData as FormDataNode } from 'formdata-node';
              import { fileFromPathSync } from 'formdata-node/file-from-path';

              const mimeType = mime.getType(path.extname(path_to_file));
              const file = fileFromPathSync(path_to_file, file_name, {
                type: mimeType,
              });

              const form = new FormDataNode();
              form.append('file', file, file_name);
              form.append('ownerID', owner_id);

              fetch('https://api.cord.com/v1/files', {
                method: 'POST', 
                body: form,
                headers: {
                  Authorization: `Bearer <your_auth_token>`
                }
              });
              

              import path from 'path';
              import mime from 'mime';
              import { FormData as FormDataNode } from 'formdata-node';
              import { fileFromPathSync } from 'formdata-node/file-from-path';

              const mimeType = mime.getType(path.extname(path_to_file));
              const file = fileFromPathSync(path_to_file, file_name, {
                type: mimeType,
              });

              const form = new FormDataNode();
              form.append('file', file, file_name);
              form.append('ownerID', owner_id);

              fetch('https://api.cord.com/v1/files', {
                method: 'POST', 
                body: form,
                headers: {
                  Authorization: `Bearer <your_auth_token>`
                }
              });
              
Copy

Ask Cordy