Skip to content

Commit

Permalink
Fix: Handle undefined fileName during attachment download
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
kidroca committed Oct 31, 2023
1 parent 3e88eed commit 0060380
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/libs/fileDownload/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function hasAndroidPermission() {
/**
* Handling the download
* @param {String} url
* @param {String} fileName
* @param {String} [fileName]
* @returns {Promise<Void>}
*/
function handleDownload(url, fileName) {
Expand All @@ -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://');

Expand Down Expand Up @@ -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<Void>}
*/
export default function fileDownload(url, fileName) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/fileDownload/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>}
*/
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:
Expand Down
4 changes: 2 additions & 2 deletions src/libs/fileDownload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 0060380

Please sign in to comment.