From 093398c16215d77edb7c89e1960e90d6fd431592 Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Fri, 19 Jul 2024 16:25:15 +0200 Subject: [PATCH] Fix Android downloading location --- src/libs/fileDownload/index.android.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libs/fileDownload/index.android.ts b/src/libs/fileDownload/index.android.ts index adfb75bc28c4..83255231d26b 100644 --- a/src/libs/fileDownload/index.android.ts +++ b/src/libs/fileDownload/index.android.ts @@ -96,7 +96,7 @@ function handleDownload(url: string, fileName?: string, successMessage?: string) }); } -const postDownloadFile = (url: string, fileName?: string, formData?: FormData, onDownloadFailed?: () => void) => { +const postDownloadFile = (url: string, fileName?: string, formData?: FormData, onDownloadFailed?: () => void): Promise => { const fetchOptions: RequestInit = { method: 'POST', body: formData, @@ -115,7 +115,19 @@ const postDownloadFile = (url: string, fileName?: string, formData?: FormData, o return RNFS.writeFile(downloadPath, fileData, 'utf8').then(() => downloadPath); }) - .then(() => { + .then((downloadPath) => + RNFetchBlob.MediaCollection.copyToMediaStore( + { + name: FileUtils.getFileName(downloadPath), + parentFolder: 'Expensify', + mimeType: null, + }, + 'Download', + downloadPath, + ).then(() => downloadPath), + ) + .then((downloadPath) => { + RNFetchBlob.fs.unlink(downloadPath); FileUtils.showSuccessAlert(); }) .catch(() => {