From 006038059efe160de4979d930409c21cf3d8822c Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Mon, 21 Aug 2023 11:21:29 +0300 Subject: [PATCH] Fix: Handle undefined fileName during attachment download - Addressed issue where attachments, especially those added via drag and drop, lacked the `fileName` attribute, causing download failures. - Enhanced the fallback mechanism to generate file name from URL when `fileName` is missing. - Updated the fileName logic in `fileDownload` across iOS, Android, and web implementations. --- src/libs/fileDownload/index.android.js | 6 +++--- src/libs/fileDownload/index.ios.js | 4 ++-- src/libs/fileDownload/index.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/fileDownload/index.android.js b/src/libs/fileDownload/index.android.js index c3528b579f67..5f50ad27ef70 100644 --- a/src/libs/fileDownload/index.android.js +++ b/src/libs/fileDownload/index.android.js @@ -32,7 +32,7 @@ function hasAndroidPermission() { /** * Handling the download * @param {String} url - * @param {String} fileName + * @param {String} [fileName] * @returns {Promise} */ function handleDownload(url, fileName) { @@ -41,7 +41,7 @@ function handleDownload(url, fileName) { // Android files will download to Download directory const path = dirs.DownloadDir; - const attachmentName = FileUtils.appendTimeToFileName(fileName) || FileUtils.getAttachmentName(url); + const attachmentName = fileName ? FileUtils.appendTimeToFileName(fileName) : FileUtils.getAttachmentName(url); const isLocalFile = url.startsWith('file://'); @@ -96,7 +96,7 @@ function handleDownload(url, fileName) { /** * Checks permission and downloads the file for Android * @param {String} url - * @param {String} fileName + * @param {String} [fileName] * @returns {Promise} */ export default function fileDownload(url, fileName) { diff --git a/src/libs/fileDownload/index.ios.js b/src/libs/fileDownload/index.ios.js index 1599e919d28a..252c40797e7a 100644 --- a/src/libs/fileDownload/index.ios.js +++ b/src/libs/fileDownload/index.ios.js @@ -68,14 +68,14 @@ function downloadVideo(fileUrl, fileName) { /** * Download the file based on type(image, video, other file types)for iOS * @param {String} fileUrl - * @param {String} fileName + * @param {String} [fileName] * @returns {Promise} */ export default function fileDownload(fileUrl, fileName) { return new Promise((resolve) => { let fileDownloadPromise = null; const fileType = FileUtils.getFileType(fileUrl); - const attachmentName = FileUtils.appendTimeToFileName(fileName) || FileUtils.getAttachmentName(fileUrl); + const attachmentName = fileName ? FileUtils.appendTimeToFileName(fileName) : FileUtils.getAttachmentName(fileUrl); switch (fileType) { case CONST.ATTACHMENT_FILE_TYPE.IMAGE: diff --git a/src/libs/fileDownload/index.js b/src/libs/fileDownload/index.js index c100f73c2fcf..35e22519d137 100644 --- a/src/libs/fileDownload/index.js +++ b/src/libs/fileDownload/index.js @@ -6,7 +6,7 @@ import tryResolveUrlFromApiRoot from '../tryResolveUrlFromApiRoot'; /** * Downloading attachment in web, desktop * @param {String} url - * @param {String} fileName + * @param {String} [fileName] * @returns {Promise} */ export default function fileDownload(url, fileName) { @@ -32,7 +32,7 @@ export default function fileDownload(url, fileName) { link.style.display = 'none'; link.setAttribute( 'download', - FileUtils.appendTimeToFileName(fileName) || FileUtils.getAttachmentName(url), // generating the file name + fileName ? FileUtils.appendTimeToFileName(fileName) : FileUtils.getAttachmentName(url), // generating the file name ); // Append to html link element page