Skip to main content
POST
/
files
JavaScript
import Moonbase from '@moonbaseai/sdk';

const client = new Moonbase({
  apiKey: process.env['MOONBASE_API_KEY'], // This is the default and can be omitted
});

const moonbaseFile = await client.files.upload({ file: fs.createReadStream('path/to/file') });

console.log(moonbaseFile.id);
{
  "id": "1CLJt2v17V1yuCdrUwA4PW",
  "type": "file",
  "name": "Example",
  "filename": "test.txt",
  "size": 3,
  "download_url": "https://api.moonbase.ai/asset_redirects/1CLJt2v1cFRDidcZsXKEd4?token=eyJfcmFpbHMiOnsiZGF0YSI6eyJpZCI6IjFDTEp0MnYxY0ZSRGlkY1pzWEtFZDQiLCJuYW1lIjoiZmlsZSIsInJlY29yZF90eXBlIjoiTGlicmFyeUFzc2V0IiwicmVjb3JkX2lkIjoiMUNMSnQydjE3VjF5dUNkclV3QTRQVyIsImJsb2JfaWQiOiIxQ0xKdDJ2MU1zRGJvdjhEQkVFZVdIIiwiY3JlYXRlZF9hdCI6IjIwMjUtMDItMTdUMTY6MDA6MDAuMDAwWiJ9LCJleHAiOiIyMDI1LTAyLTE3VDE3OjAwOjAwLjAwMFoiLCJwdXIiOiJyZWRpcmVjdCJ9fQ--44cffd59d4a0320b941925fafa70a33ee21ef3c0",
  "associations": [],
  "created_at": "2025-02-17T16:00:00.000Z",
  "updated_at": "2025-02-17T16:00:00.000Z"
}

Authorizations

Authorization
string
header
required

Your Moonbase API key.

Body

multipart/form-data

The File to upload.

file
file
required

The File object to be uploaded.

name
string

The display name of the file.

associations
Pointer · object[]

Link the File to Moonbase items like a person, organization, deal, task, or an item in a custom collection.

Response

Upload succeeded.

The File object represents a file that has been uploaded to your library.

type
string
required

String representing the object’s type. Always file for this object.

Allowed value: "file"
id
string
required

Unique identifier for the object.

name
string
required

The display name of the file.

filename
string
required

The original filename of the uploaded file.

size
number
required

The size of the file in bytes.

download_url
string<uri>
required

A temporary, signed URL to download the file content. The URL expires after one hour.

associations
ItemPointer · object[]
required

A list of items this file is associated with.

created_at
string<date-time>
required

Time at which the object was created, as an ISO 8601 timestamp in UTC.

updated_at
string<date-time>
required

Time at which the object was last updated, as an ISO 8601 timestamp in UTC.