Skip to content

Commit

Permalink
Fix Android downloading location
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-solecki committed Jul 19, 2024
1 parent fdb5105 commit 093398c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/libs/fileDownload/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
const fetchOptions: RequestInit = {
method: 'POST',
body: formData,
Expand All @@ -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(() => {
Expand Down

0 comments on commit 093398c

Please sign in to comment.