From bd1fb5bd54374c22e15d44bb063b88f4847a34dc Mon Sep 17 00:00:00 2001 From: Albert Gasset Date: Mon, 4 Feb 2019 10:49:41 +0100 Subject: [PATCH] MOBILE-2825 core: Don't delete local files after upload --- src/core/fileuploader/providers/fileuploader.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/fileuploader/providers/fileuploader.ts b/src/core/fileuploader/providers/fileuploader.ts index 166982d34..753b4bf21 100644 --- a/src/core/fileuploader/providers/fileuploader.ts +++ b/src/core/fileuploader/providers/fileuploader.ts @@ -486,7 +486,10 @@ export class CoreFileUploaderProvider { } /** - * Upload a file to a draft area. If the file is an online file it will be downloaded and then re-uploaded. + * Upload a file to a draft area and return the draft ID. + * + * If the file is an online file it will be downloaded and then re-uploaded. + * If the file is a local file it will not be deleted from the device after upload. * * @param {any} file Online file or local FileEntry. * @param {number} [itemId] Draft ID to use. Undefined or 0 to create a new draft ID. @@ -502,7 +505,9 @@ export class CoreFileUploaderProvider { let promise, fileName; - if (file.filename && !file.name) { + const isOnline = file.filename && !file.name; + + if (isOnline) { // It's an online file. We need to download it and re-upload it. fileName = file.filename; promise = this.filepoolProvider.downloadUrl(siteId, file.url || file.fileurl, false, component, componentId, @@ -517,7 +522,7 @@ export class CoreFileUploaderProvider { return promise.then((fileEntry) => { // Now upload the file. - const options = this.getFileUploadOptions(fileEntry.toURL(), fileName, fileEntry.type, true, 'draft', itemId); + const options = this.getFileUploadOptions(fileEntry.toURL(), fileName, fileEntry.type, isOnline, 'draft', itemId); return this.uploadFile(fileEntry.toURL(), options, undefined, siteId).then((result) => { return result.itemid; @@ -527,7 +532,9 @@ export class CoreFileUploaderProvider { /** * Given a list of files (either online files or local files), upload them to a draft area and return the draft ID. + * * Online files will be downloaded and then re-uploaded. + * Local files are not deleted from the device after upload. * If there are no files to upload it will return a fake draft ID (1). * * @param {any[]} files List of files.