Skip to content

uploadMedia

The uploadMedia function uploads a binary asset (image, video, document, …) to your project’s storage. It is the JavaScript/TypeScript counterpart of the POST /resource/upload REST endpoint.

You pass a single File or Blob. The client handles the rest internally — including the chunked upload protocol used by the REST endpoint — and returns the final { name, url } of the uploaded asset.

Example (browser, using a <input type="file">):

const input = document.querySelector<HTMLInputElement>('input[type=file]');
const file = input?.files?.[0];
if (file) {
const media = await client.uploadMedia({ file });
console.log(media.url); // https://storage.contentisland.net/.../filename.png
}

Interface

export interface ApiClient {
uploadMedia: (params: UploadMediaParams) => Promise<Media>;
// ... other methods
}
export interface UploadMediaParams {
file: Blob | File;
fileName?: string;
}
export interface Media {
name: string;
url: string;
}

Parameters

The function accepts a single UploadMediaParams object.

NameDescription
fileThe binary contents of the asset. In a browser, this is typically a File from a file input; in Node.js it can be a Blob.
fileNameOptional. Name to register the file under. Defaults to 'upload'. When file is a File, you usually want to pass file.name here.

Output

The function returns a Promise<Media> resolving to the final asset metadata:

const media = await client.uploadMedia({ file, fileName: file.name });
/*
{
name: 'ab12cd34-cover-image.png',
url: 'https://storage.contentisland.net/your-project/ab12cd34-cover-image.png',
}
*/

You can then use media.url directly anywhere in your application, or save it into a content field via updateContentFieldValue.