addUploadPath
2.2.1 버전부터 지원합니다.
업로드된 파일의 경로를 파일 타입(키)별로 구분해 에디터 인스턴스에 추가합니다. 등록된 경로 목록은 getUploadedFiles를 통해 가져올 수 있습니다.
매개변수
| 이름 | 타입 | 설명 |
|---|---|---|
fileType | string | 파일 타입 — 'image', 'video', 또는 'file' |
uploadPath | string | 파일이 업로드된 경로 |
예시
editor.addUploadPath('image', 'upload/path/filename.png');
사용 예시 — 이미지 업로드 개수 제한
에디터의 업로드 관련 API를 addUploadPath 및 getUploadedFiles와 함께 사용하여 이미지 개수 제한을 적용합니다.
var editorId = 'synapEditor';
var editorConfig = {};
var html = '';
var editor = new SynapEditor(editorId, editorConfig, html);
editor.setEventListener('afterUploadImage', function (e) {
var fileType = e.fileType;
var uploadPath = e.path;
// Required so that getUploadedFiles() can see this upload
e.editor.addUploadPath(fileType, uploadPath);
});
editor.setEventListener('beforeUploadImage', function (e) {
var fileType = e.fileType;
var uploadCount = e.uploadCount; // images still being uploaded
var imageCount = 0;
e.editor.getUploadedFiles(fileType).forEach(function (info) {
if (!info.isDeleted) {
imageCount++; // count images that have not been deleted
}
});
if (imageCount + uploadCount > 5) {
// Allow up to 5
e.returnValue = false; // returning false cancels the upload
alert('You may upload up to 5 images.');
}
});