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
UtilsAPI
Methods#
showLoadingDialog()#
Shows and manages a loading dialog with progress tracking
Parameters#
Parameter | Type | Description |
---|---|---|
options? | { title? : string ; message? : string | string []; cancelLabel? : string ; abortLabel? : string ; abortTitle? : string ; abortMessage? : string |
options.title? | string | - |
options.message? | string | string [] |
options.cancelLabel? | string | - |
options.abortLabel? | string | - |
options.abortTitle? | string | - |
options.abortMessage? | string | string [] |
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
Name | Type |
---|---|
dialogId | string |
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 progresscontroller.updateProgress({ value: 50, max: 100 });
// Show successcontroller.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#
Parameter | Type | Description |
---|---|---|
options? | T | Export 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 exportconst imageResult = await cesdk.utils.export({ mimeType: 'image/png', pngCompressionLevel: 7});
// Video exportconst 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#
Parameter | Type | Description |
---|---|---|
options | { accept : string ; returnType? : T ; } | Options for the file load operation |
options.accept | string | - |
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 fileconst text = await cesdk.utils.loadFile({ accept: '.txt', returnType: 'text'});
// Load an image as blobconst 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#
Parameter | Type | Description |
---|---|---|
file | string | Blob |
mimeType? | FileMimeType | The MIME type of the content |
Returns#
Promise
<void
>
Example#
// Download a text fileawait cesdk.utils.downloadFile('Hello World', 'text/plain');
// Download a blobconst 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#
Parameter | Type | Description |
---|---|---|
file | File | The file to upload |
context? | UploadCallbackContext | Optional 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>