Skip to content

Commit

Permalink
Merge pull request Expensify#31474 from mkhutornyi/fix-31442
Browse files Browse the repository at this point in the history
fix image not downloading in offline mode
  • Loading branch information
techievivek authored Nov 17, 2023
2 parents 88b1de1 + bd1706a commit 9fc8d7a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ const CONST = {
ATTACHMENT_SOURCE_ATTRIBUTE: 'data-expensify-source',
ATTACHMENT_PREVIEW_ATTRIBUTE: 'src',
ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE: 'data-name',
ATTACHMENT_LOCAL_URL_PREFIX: ['blob:', 'file:'],

ATTACHMENT_PICKER_TYPE: {
FILE: 'file',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function extractAttachmentsFromReport(parentReportAction, reportActions, transac

if (TransactionUtils.hasReceipt(transaction)) {
const {image} = ReceiptUtils.getThumbnailAndImageURIs(transaction);
const isLocalFile = typeof image === 'string' && (image.startsWith('blob:') || image.startsWith('file:'));
const isLocalFile = typeof image === 'string' && _.some(CONST.ATTACHMENT_LOCAL_URL_PREFIX, (prefix) => image.startsWith(prefix));
attachments.unshift({
source: tryResolveUrlFromApiRoot(image),
isAuthTokenRequired: !isLocalFile,
Expand Down
4 changes: 3 additions & 1 deletion src/libs/fileDownload/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import _ from 'lodash';
import * as ApiUtils from '@libs/ApiUtils';
import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot';
import * as Link from '@userActions/Link';
import CONST from '@src/CONST';
import * as FileUtils from './FileUtils';

/**
Expand All @@ -11,7 +13,7 @@ import * as FileUtils from './FileUtils';
*/
export default function fileDownload(url, fileName) {
const resolvedUrl = tryResolveUrlFromApiRoot(url);
if (!resolvedUrl.startsWith(ApiUtils.getApiRoot())) {
if (!resolvedUrl.startsWith(ApiUtils.getApiRoot()) && !_.some(CONST.ATTACHMENT_LOCAL_URL_PREFIX, (prefix) => resolvedUrl.startsWith(prefix))) {
// Different origin URLs might pose a CORS issue during direct downloads.
// Opening in a new tab avoids this limitation, letting the browser handle the download.
Link.openExternalLink(url);
Expand Down

0 comments on commit 9fc8d7a

Please sign in to comment.