addUploadPath

Release 2.2.1+

Adds an uploaded file's path to the editor instance, keyed by file type. The list of registered paths can be retrieved via getUploadedFiles.

Parameters

NameTypeDescription
fileTypestringFile type — 'image', 'video', or 'file'
uploadPathstringPath where the file was uploaded

Example

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

Usage example — limiting image upload count

Use the editor's upload-related APIs together with addUploadPath and getUploadedFiles to enforce an image count limit.

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.');
  }
});