Page tree
Skip to end of metadata
Go to start of metadata

RELEASE 2.2.1 OR ABOVE

This object adds a upload path for the file type of uploaded file.

You may get the result from editor.getUploadedFiles() only when you have set the upload path during the upload through this method.

Parameters:

Name

Type

Description

fileTypeStringFile type whose upload path shall be added. ("image", "video", "file")
uploadPathStringPath in which the file is uploaded.


Example:

editor.addUploadPath("image", "upload/path/filename.png");



Example

1. Limiting the Number of Image Upload

You may limit the maximum number of image upload using API related to the file upload provided by Synap Editor.


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); // 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) { // Allow up to 5 uploads
		e.returnValue = false; // Cancel the upload by returning false through returnValue
		alert('Five images can be uploaded at most');
	}
});


Relevant APIs



  • No labels