FileLoader (upload)
@ckeditor/ckeditor5-upload/src/filerepository
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
module:upload/filerepository~FileLoader#data
Returns the file data. To read its data, you need for first load the file by using the
read()
method. -
file : Promise.<(File | null)>
module:upload/filerepository~FileLoader#file
A
Promise
which resolves to aFile
instance associated with this file loader. -
id : Number
module:upload/filerepository~FileLoader#id
readonly
Unique id of FileLoader instance.
-
status : String
module:upload/filerepository~FileLoader#status
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->
reading ->error
When uploading status can change in a following way:
idle
->uploading
->idle
idle
->uploading
->aborted
idle
->uploading
->error
-
uploadResponse : Object | null
module:upload/filerepository~FileLoader#uploadResponse
readonly observable
Response of the upload.
-
uploadTotal : Number | null
module:upload/filerepository~FileLoader#uploadTotal
readonly observable
Number of total bytes to upload.
-
uploaded : Number
module:upload/filerepository~FileLoader#uploaded
readonly observable
Number of bytes uploaded.
-
uploadedPercent : Number
module:upload/filerepository~FileLoader#uploadedPercent
readonly observable
Upload progress in percents.
-
_filePromiseWrapper : FilePromiseWrapper
module:upload/filerepository~FileLoader#_filePromiseWrapper
protected
Additional wrapper over the initial file promise passed to this loader.
-
_reader : FileReader
module:upload/filerepository~FileLoader#_reader
protected
FileReader used by FileLoader.
-
_adapter : UploadAdapter
module:upload/filerepository~FileLoader#_adapter
private
Adapter instance associated with this file loader.
Methods
-
constructor( filePromise, uploadAdapterCreator )
module:upload/filerepository~FileLoader#constructor
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()
module:upload/filerepository~FileLoader#abort
Aborts loading process.
-
read() → Promise.<String>
module:upload/filerepository~FileLoader#read
Reads file using
FileReader
.Throws CKEditorError
filerepository-read-wrong-status
when status is different thanidle
.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>
module:upload/filerepository~FileLoader#upload
Reads file using the provided
UploadAdapter
.Throws CKEditorError
filerepository-upload-wrong-status
when status is different thanidle
. 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
module:upload/filerepository~FileLoader#_createFilePromiseWrapper
private
Wraps a given file promise into another promise giving additional control (resolving, rejecting, checking if fulfilled) over it.
-
_destroy()
module:upload/filerepository~FileLoader#_destroy
private
Performs cleanup.
Events
-
change:status( eventInfo, name, value, oldValue )
module:upload/filerepository~FileLoader#event:change:status
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 ornull
, if operation should remove property.oldValue : String
Old value of the
status
property with given key ornull
, if property was not set before.
-
change:uploadResponse( eventInfo, name, value, oldValue )
module:upload/filerepository~FileLoader#event:change:uploadResponse
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 ornull
, if operation should remove property.oldValue : Object | null
Old value of the
uploadResponse
property with given key ornull
, if property was not set before.
-
change:uploadTotal( eventInfo, name, value, oldValue )
module:upload/filerepository~FileLoader#event:change:uploadTotal
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 ornull
, if operation should remove property.oldValue : Number | null
Old value of the
uploadTotal
property with given key ornull
, if property was not set before.
-
change:uploaded( eventInfo, name, value, oldValue )
module:upload/filerepository~FileLoader#event:change:uploaded
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 ornull
, if operation should remove property.oldValue : Number
Old value of the
uploaded
property with given key ornull
, if property was not set before.
-
change:uploadedPercent( eventInfo, name, value, oldValue )
module:upload/filerepository~FileLoader#event:change:uploadedPercent
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 ornull
, if operation should remove property.oldValue : Number
Old value of the
uploadedPercent
property with given key ornull
, if property was not set before.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.