Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Mar 15, 2019
2 parents 6995d74 + 20fe438 commit e209ca2
Showing 1 changed file with 44 additions and 49 deletions.
93 changes: 44 additions & 49 deletions docs/framework/guides/deep-dive/upload-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class MyUploadAdapter {
} );

// Return a promise that will be resolved when the file is uploaded.
return server.upload( loader.file );
return loader.file
.then( file => server.upload( file ) );
}

// Aborts the upload process.
Expand Down Expand Up @@ -182,11 +183,12 @@ class MyUploadAdapter {

// Starts the upload process.
upload() {
return new Promise( ( resolve, reject ) => {
this._initRequest();
this._initListeners( resolve, reject );
this._sendRequest( reject );
} );
return this.loader.file
.then( file => new Promise( ( resolve, reject ) => {
this._initRequest();
this._initListeners( resolve, reject, file );
this._sendRequest( file );
} ) );
}

// Aborts the upload process.
Expand Down Expand Up @@ -237,10 +239,10 @@ class MyUploadAdapter {
// ...

// Initializes XMLHttpRequest listeners.
_initListeners( resolve, reject ) {
_initListeners( resolve, reject, file ) {
const xhr = this.xhr;
const loader = this.loader;
const genericErrorText = 'Couldn\'t upload file:' + ` ${ loader.file.name }.`;
const genericErrorText = `Couldn't upload file: ${ file.name }.`;

xhr.addEventListener( 'error', () => reject( genericErrorText ) );
xhr.addEventListener( 'abort', () => reject() );
Expand Down Expand Up @@ -292,23 +294,19 @@ class MyUploadAdapter {
// ...

// Prepares the data and sends the request.
_sendRequest( reject ) {
this.loader.file
.then( file => {
// Prepare the form data.
const data = new FormData();

data.append( 'upload', file );

// Important note: This is the right place to implement security mechanisms
// like authentication and CSRF protection. For instance, you can use
// XMLHttpRequest.setRequestHeader() to set the request headers containing
// the CSRF token generated earlier by your application.

// Send the request.
this.xhr.send( data );
} )
.catch( reject );
_sendRequest( file ) {
// Prepare the form data.
const data = new FormData();

data.append( 'upload', file );

// Important note: This is the right place to implement security mechanisms
// like authentication and CSRF protection. For instance, you can use
// XMLHttpRequest.setRequestHeader() to set the request headers containing
// the CSRF token generated earlier by your application.

// Send the request.
this.xhr.send( data );
}
}
```
Expand Down Expand Up @@ -416,11 +414,12 @@ class MyUploadAdapter {

// Starts the upload process.
upload() {
return new Promise( ( resolve, reject ) => {
this._initRequest();
this._initListeners( resolve, reject );
this._sendRequest( reject );
} );
return this.loader.file
.then( file => new Promise( ( resolve, reject ) => {
this._initRequest();
this._initListeners( resolve, reject, file );
this._sendRequest( file );
} ) );
}

// Aborts the upload process.
Expand All @@ -443,10 +442,10 @@ class MyUploadAdapter {
}

// Initializes XMLHttpRequest listeners.
_initListeners( resolve, reject ) {
_initListeners( resolve, reject, file ) {
const xhr = this.xhr;
const loader = this.loader;
const genericErrorText = 'Couldn\'t upload file:' + ` ${ loader.file.name }.`;
const genericErrorText = `Couldn't upload file: ${ file.name }.`;

xhr.addEventListener( 'error', () => reject( genericErrorText ) );
xhr.addEventListener( 'abort', () => reject() );
Expand Down Expand Up @@ -486,23 +485,19 @@ class MyUploadAdapter {
}

// Prepares the data and sends the request.
_sendRequest( reject ) {
this.loader.file
.then( file => {
// Prepare the form data.
const data = new FormData();

data.append( 'upload', file );

// Important note: This is the right place to implement security mechanisms
// like authentication and CSRF protection. For instance, you can use
// XMLHttpRequest.setRequestHeader() to set the request headers containing
// the CSRF token generated earlier by your application.

// Send the request.
this.xhr.send( data );
} )
.catch( reject );
_sendRequest( file ) {
// Prepare the form data.
const data = new FormData();

data.append( 'upload', file );

// Important note: This is the right place to implement security mechanisms
// like authentication and CSRF protection. For instance, you can use
// XMLHttpRequest.setRequestHeader() to set the request headers containing
// the CSRF token generated earlier by your application.

// Send the request.
this.xhr.send( data );
}
}

Expand Down

0 comments on commit e209ca2

Please sign in to comment.