本文整理匯總了TypeScript中@core/fileuploader/providers/helper.CoreFileUploaderHelperProvider.selectAndUploadFile方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CoreFileUploaderHelperProvider.selectAndUploadFile方法的具體用法?TypeScript CoreFileUploaderHelperProvider.selectAndUploadFile怎麽用?TypeScript CoreFileUploaderHelperProvider.selectAndUploadFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@core/fileuploader/providers/helper.CoreFileUploaderHelperProvider
的用法示例。
在下文中一共展示了CoreFileUploaderHelperProvider.selectAndUploadFile方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: uploadPrivateFile
/**
* Select a file, upload it and move it to private files.
*
* @param {any} [info] Private files info. See AddonFilesProvider.getPrivateFilesInfo.
* @return {Promise<any>} Promise resolved when a file is uploaded, rejected otherwise.
*/
uploadPrivateFile(info?: any): Promise<any> {
// Calculate the max size.
const currentSite = this.sitesProvider.getCurrentSite();
let maxSize = currentSite.getInfo().usermaxuploadfilesize,
userQuota = currentSite.getInfo().userquota;
if (userQuota === 0) {
// 0 means ignore user quota. In the app it is -1.
userQuota = -1;
} else if (userQuota > 0 && typeof info != 'undefined') {
userQuota = userQuota - info.filesizewithoutreferences;
}
if (typeof userQuota != 'undefined') {
// Use the minimum value.
maxSize = Math.min(maxSize, userQuota);
}
// Select and upload the file.
return this.fileUploaderHelper.selectAndUploadFile(maxSize).then((result) => {
if (!result) {
return Promise.reject(null);
}
// File uploaded. Move it to private files.
const modal = this.domUtils.showModalLoading('core.fileuploader.uploading', true);
return this.filesProvider.moveFromDraftToPrivate(result.itemid).catch((error) => {
this.domUtils.showErrorModalDefault(error, 'core.fileuploader.errorwhileuploading', true);
return Promise.reject(null);
}).finally(() => {
modal.dismiss();
});
}).then(() => {
this.domUtils.showToast('core.fileuploader.fileuploaded', true, undefined, 'core-toast-success');
});
}