Report an issue
Class

FileLoader (upload)

@ckeditor/ckeditor5-upload/src/filerepository

class

File loader class. It is used to control the process of file reading and uploading using specified adapter.

Filtering

Properties

  • file : File

    readonly

    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 ->abortedidle->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.

  • _reader : FileReader

    protected

    FileReader used by FileLoader.

  • _adapter : UploadAdapter

    private

    Adapter instance associated with this file loader.

Methods

  • constructor( file, adapter )

    Creates a new instance of FileLoader.

    Parameters

    file : File

    A native file instance.

    adapter : UploadAdapter
  • abort()

    Aborts loading process.

  • read() → Promise

    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

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

  • upload() → Promise

    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

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

  • _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.