Class

FileLoader (upload)

@ckeditor/ckeditor5-upload/src/filerepository

class

File loader class.

It is used to control the process of reading the file and uploading it using the specified upload adapter.

Filtering

Properties

  • data : File | undefined

    Returns the file data. To read its data, you need for first load the file by using the read() method.

  • file : Promise.<(File | null)>

    A Promise which resolves to a File instance associated with this file loader.

  • id : Number

    readonly

    Unique id of FileLoader instance.

  • status : String

    readonly observable

    Current status of FileLoader. It can be one of the following:

    • 'idle',
    • 'reading',
    • 'uploading',
    • 'aborted',
    • 'error'.

    When reading status can change in a following way:

    idle -> reading -> idle idle -> reading -> aborted idle->reading -> error

    When uploading status can change in a following way:

    idle -> uploading -> idle idle -> uploading -> aborted idle -> uploading -> error

  • uploadResponse : Object | null

    readonly observable

    Response of the upload.

  • uploadTotal : Number | null

    readonly observable

    Number of total bytes to upload.

  • uploaded : Number

    readonly observable

    Number of bytes uploaded.

  • uploadedPercent : Number

    readonly observable

    Upload progress in percents.

  • _filePromiseWrapper : FilePromiseWrapper

    protected

    Additional wrapper over the initial file promise passed to this loader.

  • _reader : FileReader

    protected

    FileReader used by FileLoader.

  • _adapter : UploadAdapter

    private

    Adapter instance associated with this file loader.

Methods

  • constructor( filePromise, uploadAdapterCreator )

    Creates a new instance of FileLoader.

    Parameters

    filePromise : Promise.<File>

    A promise which resolves to a file instance.

    uploadAdapterCreator : function

    The function which returns UploadAdapter instance.

  • abort()

    Aborts loading process.

  • read() → Promise.<String>

    Reads file using FileReader.

    Throws CKEditorError filerepository-read-wrong-status when status is different than idle.

    Example usage:

    fileLoader.read()
    	.then( data => { ... } )
    	.catch( err => {
    		if ( err === 'aborted' ) {
    			console.log( 'Reading aborted.' );
    		} else {
    			console.log( 'Reading error.', err );
    		}
    	} );

    Returns

    Promise.<String>

    Returns promise that will be resolved with read data. Promise will be rejected if error occurs or if read process is aborted.

  • upload() → Promise.<Object>

    Reads file using the provided UploadAdapter.

    Throws CKEditorError filerepository-upload-wrong-status when status is different than idle. Example usage:

    fileLoader.upload()
    	.then( data => { ... } )
    	.catch( e => {
    		if ( e === 'aborted' ) {
    			console.log( 'Uploading aborted.' );
    		} else {
    			console.log( 'Uploading error.', e );
    		}
    	} );

    Returns

    Promise.<Object>

    Returns promise that will be resolved with response data. Promise will be rejected if error occurs or if read process is aborted.

  • _createFilePromiseWrapper( filePromise ) → FilePromiseWrapper

    private

    Wraps a given file promise into another promise giving additional control (resolving, rejecting, checking if fulfilled) over it.

    Parameters

    filePromise

    The initial file promise to be wrapped.

    Returns

    FilePromiseWrapper
  • _destroy()

    private

    Performs cleanup.

Events

  • change:status( eventInfo, name, value, oldValue )

    Fired when the status property changed value.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    name : String

    Name of the changed property (status).

    value : String

    New value of the status property with given key or null, if operation should remove property.

    oldValue : String

    Old value of the status property with given key or null, if property was not set before.

  • change:uploadResponse( eventInfo, name, value, oldValue )

    Fired when the uploadResponse property changed value.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    name : String

    Name of the changed property (uploadResponse).

    value : Object | null

    New value of the uploadResponse property with given key or null, if operation should remove property.

    oldValue : Object | null

    Old value of the uploadResponse property with given key or null, if property was not set before.

  • change:uploadTotal( eventInfo, name, value, oldValue )

    Fired when the uploadTotal property changed value.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    name : String

    Name of the changed property (uploadTotal).

    value : Number | null

    New value of the uploadTotal property with given key or null, if operation should remove property.

    oldValue : Number | null

    Old value of the uploadTotal property with given key or null, if property was not set before.

  • change:uploaded( eventInfo, name, value, oldValue )

    Fired when the uploaded property changed value.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    name : String

    Name of the changed property (uploaded).

    value : Number

    New value of the uploaded property with given key or null, if operation should remove property.

    oldValue : Number

    Old value of the uploaded property with given key or null, if property was not set before.

  • change:uploadedPercent( eventInfo, name, value, oldValue )

    Fired when the uploadedPercent property changed value.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    name : String

    Name of the changed property (uploadedPercent).

    value : Number

    New value of the uploadedPercent property with given key or null, if operation should remove property.

    oldValue : Number

    Old value of the uploadedPercent property with given key or null, if property was not set before.