Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
navigateToStartMoneyRequestStep,
updateIOUOwnerAndTotal,
} from '@libs/IOUUtils';
import isFileUploadable from '@libs/isFileUploadable';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import * as Localize from '@libs/Localize';
import Log from '@libs/Log';
Expand Down Expand Up @@ -4430,7 +4431,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
const workspaceParams =
isPolicyExpenseChatReportUtil(chatReport) && chatReport.policyID
? {
receipt: receipt instanceof Blob ? receipt : undefined,
receipt: isFileUploadable(receipt) ? receipt : undefined,
category,
tag,
taxCode,
Expand Down Expand Up @@ -4482,7 +4483,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
createdChatReportActionID,
createdIOUReportActionID,
reportPreviewReportActionID: reportPreviewAction.reportActionID,
receipt: receipt instanceof Blob ? receipt : undefined,
receipt: isFileUploadable(receipt) ? receipt : undefined,
receiptState: receipt?.state,
category,
tag,
Expand Down Expand Up @@ -4752,7 +4753,7 @@ function trackExpense(
category,
tag,
billable,
receipt: trackedReceipt instanceof Blob ? trackedReceipt : undefined,
receipt: isFileUploadable(trackedReceipt) ? trackedReceipt : undefined,
waypoints: sanitizedWaypoints,
customUnitRateID: mileageRate,
};
Expand Down Expand Up @@ -4797,7 +4798,7 @@ function trackExpense(
category,
tag,
billable,
receipt: trackedReceipt instanceof Blob ? trackedReceipt : undefined,
receipt: isFileUploadable(trackedReceipt) ? trackedReceipt : undefined,
waypoints: sanitizedWaypoints,
customUnitRateID: mileageRate,
};
Expand Down Expand Up @@ -4838,7 +4839,7 @@ function trackExpense(
createdChatReportActionID,
createdIOUReportActionID,
reportPreviewReportActionID: reportPreviewAction?.reportActionID,
receipt: trackedReceipt instanceof Blob ? trackedReceipt : undefined,
receipt: isFileUploadable(trackedReceipt) ? trackedReceipt : undefined,
receiptState: trackedReceipt?.state,
category,
tag,
Expand Down
10 changes: 10 additions & 0 deletions src/libs/isFileUploadable/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type {FileObject} from '@components/AttachmentModal';

function isFileUploadable(file: FileObject | undefined): boolean {
// Native platforms only require the object to include the `uri` property.
// Optionally, it can also have a `name` and `type` properties.
// On other platforms, the file must be an instance of `Blob` or one of its subclasses.
return !!file && 'uri' in file && !!file.uri && typeof file.uri === 'string';
}

export default isFileUploadable;
7 changes: 7 additions & 0 deletions src/libs/isFileUploadable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type {FileObject} from '@components/AttachmentModal';

function isFileUploadable(file: FileObject | undefined): boolean {
return file instanceof Blob;
}

export default isFileUploadable;
11 changes: 2 additions & 9 deletions src/libs/validateFormDataParameter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import CONST from '@src/CONST';
import getPlatform from './getPlatform';

const platform = getPlatform();
const isNativePlatform = platform === CONST.PLATFORM.ANDROID || platform === CONST.PLATFORM.IOS;
import isFileUploadable from './isFileUploadable';

/**
* Ensures no value of type `object` other than null, Blob, its subclasses, or {uri: string} (native platforms only) is passed to XMLHttpRequest.
Expand All @@ -19,10 +15,7 @@ function validateFormDataParameter(command: string, key: string, value: unknown)
return value.every((element) => isValid(element, false));
}
if (isTopLevel) {
// Native platforms only require the value to include the `uri` property.
// Optionally, it can also have a `name` and `type` props.
// On other platforms, the value must be an instance of `Blob`.
return isNativePlatform ? 'uri' in value && !!value.uri : value instanceof Blob;
return isFileUploadable(value);
}
return false;
};
Expand Down