getUploadedFiles

Release 2.2.1+

Returns the paths and deleted states of uploaded files, optionally filtered by file type.

For this to return useful data, your afterUploadFile, afterUploadImage, and afterUploadVideo event handlers must call addUploadPath to register uploaded files.

Parameters

NameTypeDescription
[fileType]string'image', 'video', or 'file'. If omitted, returns all types.

Returns

When fileType is provided:

TypeDescription
Array[{ path: '/upload/path/filename.png', isDeleted: false }, ...]

When fileType is omitted:

TypeDescription
Object{ image: [...], video: [...], file: [...] } (each entry has path and isDeleted)
  • path: upload path
  • isDeleted: whether the file has been removed from the editor

Example

var filesData  = editor.getUploadedFiles();          // all types
var filesData2 = editor.getUploadedFiles('image');   // images only

Usage Examples

1. Limiting the number of image uploads

Use the file-upload-related APIs together with the beforeUploadImage / afterUploadImage events to cap how many images may be uploaded.

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: register the upload so getUploadedFiles() can see it.
    e.editor.addUploadPath(fileType, uploadPath);
});

editor.setEventListener('beforeUploadImage', function (e) {
    var fileType = e.fileType;
    var uploadCount = e.uploadCount; // number of images currently uploading (not yet uploaded)
    var imageCount = 0;
    e.editor.getUploadedFiles(fileType).forEach(function (info) {
        if (!info.isDeleted) {
            imageCount++; // count images that are still present
        }
    });
    if (imageCount + uploadCount >= 5) { // allow only up to 5
        e.returnValue = false; // cancel the upload
        alert('Only up to 5 images can be uploaded'); // "You can upload up to 5 images only."
    }
});