Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/adapters/simpleuploadadapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ class Adapter {
return reject( response && response.error && response.error.message ? response.error.message : genericErrorText );
}

if ( this.options.transformResponse ) {
return resolve(this.options.transformResponse(response));
}

resolve( response.url ? { default: response.url } : response.urls );
} );

Expand Down Expand Up @@ -210,6 +214,12 @@ class Adapter {

data.append( 'upload', file );

if ( this.options.params ) {
Object.keys(this.options.params).forEach((key) => {
data.append(key, this.options.params[key]);
});
}

// Send the request.
this.xhr.send( data );
}
Expand All @@ -227,6 +237,10 @@ class Adapter {
* // Headers sent along with the XMLHttpRequest to the upload server.
* headers: {
* ...
* },
* // Parameters sent as form data to the upload server.
* params: {
* ...
* }
* }
* } );
Expand Down Expand Up @@ -282,3 +296,45 @@ class Adapter {
*
* @member {Object.<String, String>} module:upload/adapters/simpleuploadadapter~SimpleUploadConfig#headers
*/

/**
* An object that defines additional form data sent with
* the request to the server during the upload.
*
* ClassicEditor
* .create( editorElement, {
* simpleUpload: {
* params: {
* name: 'File name.png'
* }
* }
* } );
* .then( ... )
* .catch( ... );
*
* Learn more about the server application requirements in the
* {@glink features/image-upload/simple-upload-adapter#server-side-configuration "Server-side configuration"} section
* of the feature guide.
*
* @member {Object.<String, String>} module:upload/adapters/simpleuploadadapter~SimpleUploadConfig#params
*/

/**
* A function that transforms the server response to match
* SimpleUpload response object format.
*
* ClassicEditor
* .create( editorElement, {
* simpleUpload: {
* transformResponse: (res) => ({ default: res.url })
* }
* } );
* .then( ... )
* .catch( ... );
*
* Learn more about the server application requirements in the
* {@glink features/image-upload/simple-upload-adapter#server-side-configuration "Server-side configuration"} section
* of the feature guide.
*
* @member {Function} module:upload/adapters/simpleuploadadapter~SimpleUploadConfig#params
*/