사이냅에디터에서 제공하는 파일업로드 관련 API를 활용하여 이미지 업로드 수를 제한 할 수 있습니다You may limit the maximum number of image upload using API related to the file upload provided by Synap Editor.
Code Block | ||||
---|---|---|---|---|
| ||||
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; e.editor.addUploadPath(fileType, uploadPath); // editor.getUploadedFiles() 을 통해 업로드된 파일을 확인하려면 반드시 사용 You must use this to check the file uploaded through editor.getUploadedFiles() }); editor.setEventListener('beforeUploadImage', function (e) { var fileType = e.fileType; var uploadCount = e.uploadCount; //Number 업로드of 중인files 이미지being 수uploaded (아직 업로드 되지 않은the number of files to be uploaded whose upload is not completed yet) var imageCount = 0; e.editor.getUploadedFiles(fileType).forEach(function (info) { if (!info.isDeleted) { imageCount++; // 삭제되지 않은 이미지 개수 세기Count the number of images not deleted } }); if (imageCount + uploadCount >= 5) { // 5개 까지만 허용하기Allow up to 5 uploads e.returnValue = false; // returnValue로 false를 반환해 업로드를 취소 Cancel the upload by returning false through returnValue alert('이미지는 5개까지만 업로드 가능합니다Five images can be uploaded at most'); } }); |
관련 APIRelevant APIs
...