1 回答

TA貢獻1802條經驗 獲得超6個贊
第一個問題:如何在 upload() 方法中鏈接兩個異步函數?
從這里:https ://thoughtbot.com/blog/chaining-events-like-a-boss
例子:
const timeUserRequest = async () => {
const before = await getCurrentTimeAsync()
await getUserDataViaHttp()
const after = await getCurrentTimeAsync()
return (after - before)
};
第二個問題:如何將收到的 URL 傳遞給 CK 編輯器?
你是如何提出你的要求的?你看到這個例子了嗎?
class MyUploadAdapter {
// ...
// Initializes XMLHttpRequest listeners.
_initListeners( resolve, reject, file ) {
const xhr = this.xhr;
const loader = this.loader;
const genericErrorText = `Couldn't upload file: ${ file.name }.`;
xhr.addEventListener( 'error', () => reject( genericErrorText ) );
xhr.addEventListener( 'abort', () => reject() );
xhr.addEventListener( 'load', () => {
const response = xhr.response;
// This example assumes the XHR server's "response" object will come with
// an "error" which has its own "message" that can be passed to reject()
// in the upload promise.
//
// Your integration may handle upload errors in a different way so make sure
// it is done properly. The reject() function must be called when the upload fails.
if ( !response || response.error ) {
return reject( response && response.error ? response.error.message : genericErrorText );
}
// If the upload is successful, resolve the upload promise with an object containing
// at least the "default" URL, pointing to the image on the server.
// This URL will be used to display the image in the content. Learn more in the
// UploadAdapter#upload documentation.
resolve( {
default: response.url
} );
} );
// Upload progress when it is supported. The file loader has the #uploadTotal and #uploaded
// properties which are used e.g. to display the upload progress bar in the editor
// user interface.
if ( xhr.upload ) {
xhr.upload.addEventListener( 'progress', evt => {
if ( evt.lengthComputable ) {
loader.uploadTotal = evt.total;
loader.uploaded = evt.loaded;
}
} );
}
}
}
添加回答
舉報