setCustomUploadFunction

Release 2.10.0 and above.

Sets the user function for file uploads. When this function is set, the internal file upload logic is not used; instead, the specified user function is called.

Parameters:

NameTypeDescription
funcFunctionThe user function used for file uploads.

Example:

// Regular function example
editor.setCustomUploadFunction((file, uploadFileType) => {
    // File upload handling
    return url;
});

Release 2.15.2301 and above.

// Async function example (async)
editor.setCustomUploadFunction(async (file, uploadFileType) => {
    const url = await new Promise(resolve => setTimeout(resolve, 1000)); // File upload handling
    return url;
});
// Async function example (promise)
editor.setCustomUploadFunction((file, uploadFileType) => {
    return new Promise((resolve, reject) => { // File upload handling
        setTimeout(() => {
            resolve(url);
        }, 1000);
    });
});

Definition of the user function

The user upload function must be defined as follows.

Parameters:

NameTypeDescription
fileFileThe file to upload through the editor.
fileTypeStringThe file type (image, video, file).

Return:

TypeDescription
StringURL or path accessible by the browser.

Important: The custom upload function must return a URL (or path) that allows access to the uploaded file after the file is uploaded.

Example:

function customUpload(file, fileType) {
    // File upload handling
    return url;
}