setCustomUploadFunction
2.10.0 버전부터 지원합니다.
파일 업로드를 위한 사용자 정의 함수를 설정합니다. 이 함수가 설정되면 내부 파일 업로드 로직이 사용되지 않고, 대신 지정한 사용자 정의 함수가 호출됩니다.
매개변수
| 이름 | 타입 | 설명 |
|---|---|---|
func | Function | 파일 업로드에 사용하는 사용자 정의 함수입니다. |
예시
// Regular function example
editor.setCustomUploadFunction((file, uploadFileType) => {
// File upload handling
return url;
});
2.15.2301 버전부터 지원합니다.
// 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);
});
});
사용자 정의 함수 작성 방법
사용자 정의 업로드 함수는 다음과 같이 정의되어야 합니다.
매개변수
| 이름 | 타입 | 설명 |
|---|---|---|
file | File | 에디터를 통해 업로드할 파일입니다. |
fileType | String | 파일 타입 (image, video, file)입니다. |
반환값
| 타입 | 설명 |
|---|---|
| String | 브라우저에서 접근 가능한 URL 또는 경로. |
중요: 사용자 정의 업로드 함수는 파일이 업로드된 후 업로드된 파일에 접근할 수 있는 URL(또는 경로)을 반환해야 합니다.
예시
function customUpload(file, fileType) {
// File upload handling
return url;
}