All available operations for managing files
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.
POST https://api.cord.com/v1/files
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
parameter.If successful, the response will be:
{
"success": true,
"message": "✅ File created.",
"fileID": "12345678-90ab-cdef-1234-567890abcdef"
}
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>`
}
});
Not finding the answer you need? Ask our Developer Community