Search
Loading...
Skip to content

Class: UtilsAPI

UtilsAPI provides utility functions for common operations in the Creative Engine SDK.

This API includes utilities for:

  • Creating and managing loading dialogs
  • Exporting content (images, PDFs, videos)
  • Loading and downloading files
  • Local file uploads

Constructors#

Constructor#


UtilsAPI

Methods#

showLoadingDialog()#


Shows and manages a loading dialog with progress tracking

Parameters#

ParameterTypeDescription
options?{ title?: string; message?: stringstring[]; cancelLabel?: string; abortLabel?: string; abortTitle?: string; abortMessage?: string
options.title?string-
options.message?stringstring[]
options.cancelLabel?string-
options.abortLabel?string-
options.abortTitle?string-
options.abortMessage?stringstring[]
options.size?"regular""large"
options.clickOutsideToClose?boolean-
options.progress?DialogProgress-
options.onDone?() => void-
options.onAbort?() => void-

Returns#

object

A controller object for managing the dialog

NameType
dialogIdstring
updateProgress()(progress) => void
showSuccess()(options) => void
showError()(options) => void
close()() => void

Example#

const controller = cesdk.utils.showLoadingDialog({
title: 'Exporting',
message: 'Please wait...',
onAbort: () => console.log('Aborted')
});
// Update progress
controller.updateProgress({ value: 50, max: 100 });
// Show success
controller.showSuccess({
title: 'Success',
message: 'Export completed!'
});

Signature#

showLoadingDialog(options?: object): object

export()#


Exports content with a loading dialog and progress tracking. Automatically handles both static exports (images, PDFs) and video exports based on MIME type.

Type Parameters#

Type Parameter
T extends

Parameters#

ParameterTypeDescription
options?TExport options. Type inference based on mimeType.

Returns#

Promise<{ blobs: Blob[]; options: T extends VideoExportOptions ? OnExportVideoOptions : OnExportOptions; }>

Export result - either blobs array for static or single blob for video

Example#

// Image export
const imageResult = await cesdk.utils.export({
mimeType: 'image/png',
pngCompressionLevel: 7
});
// Video export
const videoResult = await cesdk.utils.export({
mimeType: 'video/mp4',
onProgress: (rendered, encoded, total) => console.log(`${rendered}/${total}`)
});

Signature#

export(options?: T): Promise<object>

loadFile()#


Opens a file picker dialog for the user to select a file

Type Parameters#

Type Parameter
T extends "text"

Parameters#

ParameterTypeDescription
options{ accept: string; returnType?: T; }Options for the file load operation
options.acceptstring-
options.returnType?T-

Returns#

Promise<T extends "dataURL" ? string : T extends "text" ? string : T extends "blob" ? Blob : T extends "arrayBuffer" ? ArrayBuffer : File>

The loaded file content in the requested format

Example#

// Load a text file
const text = await cesdk.utils.loadFile({
accept: '.txt',
returnType: 'text'
});
// Load an image as blob
const blob = await cesdk.utils.loadFile({
accept: 'image/*',
returnType: 'blob'
});

Signature#

loadFile(options: object): Promise<T extends "dataURL" ? string : T extends "text" ? string : T extends "blob" ? Blob : T extends "arrayBuffer" ? ArrayBuffer : File>

downloadFile()#


Downloads a blob or string as a file to the user’s device

Parameters#

ParameterTypeDescription
filestringBlob
mimeType?FileMimeTypeThe MIME type of the content

Returns#

Promise<void>

Example#

// Download a text file
await cesdk.utils.downloadFile('Hello World', 'text/plain');
// Download a blob
const blob = new Blob(['content'], { type: 'text/plain' });
await cesdk.utils.downloadFile(blob, 'text/plain');

Signature#

downloadFile(file: string | Blob, mimeType?: FileMimeType): Promise<void>

localUpload()#


Performs a local upload of a file (development only)

Note: This is meant for development testing only. In production, you should implement a proper upload handler using the callbacks API.

Parameters#

ParameterTypeDescription
fileFileThe file to upload
context?UploadCallbackContextOptional context information for the upload operation

Returns#

Promise<AssetDefinition>

The asset definition for the uploaded file

Example#

const file = new File(['content'], 'test.txt');
const asset = await cesdk.utils.localUpload(file, {
context: { source: 'user-upload' }
});

Signature#

localUpload(file: File, context?: UploadCallbackContext): Promise<AssetDefinition>