MOBILE-3473 upload: Fix big files not uploaded
parent
0ad21f4082
commit
7375102961
|
@ -64,12 +64,10 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler {
|
||||||
* @return Data.
|
* @return Data.
|
||||||
*/
|
*/
|
||||||
getData(): CoreFileUploaderHandlerData {
|
getData(): CoreFileUploaderHandlerData {
|
||||||
const isIOS = this.platform.is('ios');
|
|
||||||
|
|
||||||
const handler: CoreFileUploaderHandlerData = {
|
const handler: CoreFileUploaderHandlerData = {
|
||||||
title: isIOS ? 'core.fileuploader.more' : 'core.fileuploader.file',
|
title: 'core.fileuploader.file',
|
||||||
class: 'core-fileuploader-file-handler',
|
class: 'core-fileuploader-file-handler',
|
||||||
icon: isIOS ? 'more' : 'folder',
|
icon: 'folder',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.appProvider.isMobile()) {
|
if (this.appProvider.isMobile()) {
|
||||||
|
@ -98,7 +96,6 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler {
|
||||||
|
|
||||||
input.addEventListener('change', (evt: Event) => {
|
input.addEventListener('change', (evt: Event) => {
|
||||||
const file = input.files[0];
|
const file = input.files[0];
|
||||||
let fileName;
|
|
||||||
|
|
||||||
input.value = ''; // Unset input.
|
input.value = ''; // Unset input.
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
@ -113,17 +110,8 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName = file.name;
|
|
||||||
if (isIOS) {
|
|
||||||
// Check the name of the file and add a timestamp if needed (take picture).
|
|
||||||
const matches = fileName.match(/image\.(jpe?g|png)/);
|
|
||||||
if (matches) {
|
|
||||||
fileName = 'image_' + this.timeUtils.readableTimestamp() + '.' + matches[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upload the picked file.
|
// Upload the picked file.
|
||||||
this.uploaderHelper.uploadFileObject(file, maxSize, upload, allowOffline, fileName).then((result) => {
|
this.uploaderHelper.uploadFileObject(file, maxSize, upload, allowOffline, file.name).then((result) => {
|
||||||
this.uploaderHelper.fileUploaded(result);
|
this.uploaderHelper.fileUploaded(result);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.domUtils.showErrorModalDefault(error,
|
this.domUtils.showErrorModalDefault(error,
|
||||||
|
|
|
@ -65,8 +65,12 @@ export class CoreFileUploaderHelperProvider {
|
||||||
*/
|
*/
|
||||||
async chooseAndUploadFile(maxSize: number, upload?: boolean, allowOffline?: boolean, mimetypes?: string[]): Promise<any> {
|
async chooseAndUploadFile(maxSize: number, upload?: boolean, allowOffline?: boolean, mimetypes?: string[]): Promise<any> {
|
||||||
|
|
||||||
|
const modal = this.domUtils.showModalLoading();
|
||||||
|
|
||||||
const result = await this.fileChooser.getFile(mimetypes ? mimetypes.join(',') : undefined);
|
const result = await this.fileChooser.getFile(mimetypes ? mimetypes.join(',') : undefined);
|
||||||
|
|
||||||
|
modal.dismiss();
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// User canceled.
|
// User canceled.
|
||||||
throw this.domUtils.createCanceledError();
|
throw this.domUtils.createCanceledError();
|
||||||
|
@ -87,10 +91,6 @@ export class CoreFileUploaderHelperProvider {
|
||||||
const options = this.fileUploaderProvider.getFileUploadOptions(result.uri, result.name, result.mediaType, true);
|
const options = this.fileUploaderProvider.getFileUploadOptions(result.uri, result.name, result.mediaType, true);
|
||||||
|
|
||||||
if (upload) {
|
if (upload) {
|
||||||
const size = await this.fileProvider.getExternalFileSize(result.uri);
|
|
||||||
|
|
||||||
await this.confirmUploadFile(size, false, allowOffline);
|
|
||||||
|
|
||||||
return this.uploadFile(result.uri, maxSize, true, options);
|
return this.uploadFile(result.uri, maxSize, true, options);
|
||||||
} else {
|
} else {
|
||||||
return this.copyToTmpFolder(result.uri, false, maxSize, undefined, options);
|
return this.copyToTmpFolder(result.uri, false, maxSize, undefined, options);
|
||||||
|
|
Loading…
Reference in New Issue