이미지 업로드 개수 제한
Synap Editor에서 제공하는 파일 업로드 관련 API를 활용하여 이미지 업로드 개수를 제한할 수 있습니다.
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;
// Must be used to check uploaded files via editor.getUploadedFiles()
e.editor.addUploadPath(fileType, uploadPath);
});
editor.setEventListener('beforeUploadImage', function (e) {
var fileType = e.fileType;
var uploadCount = e.uploadCount; // Number of images being uploaded (not yet 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 only up to 5 images
e.returnValue = false; // Return false via returnValue to cancel the upload
alert('Only up to 5 images can be uploaded');
}
});