Skip to content

Commit 2adef77

Browse files
MelvinBotmadmax330
andcommitted
Add 2MB per-file size limit for Corpay onboarding document uploads
The UploadFile component had a totalFilesSizeLimit prop but no per-file size validation, allowing individual files larger than the backend's limit to be uploaded. This adds a maxFileSize prop to UploadFile and passes it (2MB) in both the Signer and BeneficialOwner upload pages. Co-authored-by: madmax330 <madmax330@users.noreply.github.com> Co-authored-by: Maxence Coulibaly <madmax330@users.noreply.github.com>
1 parent b31fcf6 commit 2adef77

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ const CONST = {
683683
NON_USD_BANK_ACCOUNT: {
684684
ALLOWED_FILE_TYPES: ['pdf', 'jpg', 'jpeg', 'png'],
685685
FILE_LIMIT: 1,
686+
MAX_FILE_SIZE: 2097152,
686687
TOTAL_FILES_SIZE_LIMIT: 5242880,
687688
PURPOSE_OF_TRANSACTION_ID: 'Intercompany_Payment',
688689
CURRENT_USER_KEY: 'currentUser',

src/components/UploadFile.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ type UploadFileProps = {
4949

5050
/** The total size limit of the files that can be selected. */
5151
totalFilesSizeLimit?: number;
52+
53+
/** The maximum size of a single file that can be selected. */
54+
maxFileSize?: number;
5255
};
5356

5457
function UploadFile({
@@ -63,6 +66,7 @@ function UploadFile({
6366
onInputChange = () => {},
6467
totalFilesSizeLimit = 0,
6568
fileLimit = 0,
69+
maxFileSize = 0,
6670
}: UploadFileProps) {
6771
const icons = useMemoizedLazyExpensifyIcons(['Close', 'Paperclip']);
6872
const {translate} = useLocalize();
@@ -73,6 +77,14 @@ function UploadFile({
7377

7478
const totalSize = resultedFiles.reduce((sum, file) => sum + (file.size ?? 0), 0);
7579

80+
if (maxFileSize) {
81+
const oversizedFile = files.find((file) => (file.size ?? 0) > maxFileSize);
82+
if (oversizedFile) {
83+
setError(translate('attachmentPicker.sizeExceededWithLimit', maxFileSize / (1024 * 1024)));
84+
return;
85+
}
86+
}
87+
7688
if (totalFilesSizeLimit) {
7789
if (totalSize > totalFilesSizeLimit) {
7890
setError(translate('attachmentPicker.sizeExceededWithValue', totalFilesSizeLimit / (1024 * 1024)));

src/pages/ReimbursementAccount/NonUSD/BeneficialOwnerInfo/BeneficialOwnerDetailsFormSubSteps/Documents.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
125125
setUploadError(error, proofOfOwnershipInputID);
126126
}}
127127
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
128+
maxFileSize={CONST.NON_USD_BANK_ACCOUNT.MAX_FILE_SIZE}
128129
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
129130
value={defaultValues[proofOfOwnershipInputID]}
130131
inputID={proofOfOwnershipInputID}
@@ -153,6 +154,7 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
153154
setUploadError(error, copyOfIDInputID);
154155
}}
155156
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
157+
maxFileSize={CONST.NON_USD_BANK_ACCOUNT.MAX_FILE_SIZE}
156158
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
157159
value={defaultValues[copyOfIDInputID]}
158160
inputID={copyOfIDInputID}
@@ -179,6 +181,7 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
179181
setUploadError(error, addressProofInputID);
180182
}}
181183
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
184+
maxFileSize={CONST.NON_USD_BANK_ACCOUNT.MAX_FILE_SIZE}
182185
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
183186
value={defaultValues[addressProofInputID]}
184187
inputID={addressProofInputID}
@@ -205,6 +208,7 @@ function Documents({onNext, isEditing, ownerBeingModifiedID}: DocumentsProps) {
205208
setUploadError(error, codiceFiscaleInputID);
206209
}}
207210
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
211+
maxFileSize={CONST.NON_USD_BANK_ACCOUNT.MAX_FILE_SIZE}
208212
acceptedFileTypes={[...CONST.NON_USD_BANK_ACCOUNT.ALLOWED_FILE_TYPES]}
209213
value={defaultValues[codiceFiscaleInputID]}
210214
inputID={codiceFiscaleInputID}

src/pages/ReimbursementAccount/NonUSD/SignerInfo/subSteps/UploadDocuments.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
149149
setUploadError(error, copyOfIDInputID);
150150
}}
151151
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
152+
maxFileSize={CONST.NON_USD_BANK_ACCOUNT.MAX_FILE_SIZE}
152153
/>
153154
<Text style={[styles.mutedTextLabel, styles.mt6]}>{translate('ownershipInfoStep.copyOfIDDescription')}</Text>
154155
{(isDocumentNeededStatus.isAddressProofNeeded ||
@@ -177,6 +178,7 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
177178
setUploadError(error, addressProofInputID);
178179
}}
179180
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
181+
maxFileSize={CONST.NON_USD_BANK_ACCOUNT.MAX_FILE_SIZE}
180182
/>
181183
<Text style={[styles.mutedTextLabel, styles.mt6]}>{translate('ownershipInfoStep.proofOfAddressDescription')}</Text>
182184
{(isDocumentNeededStatus.isProofOfDirectorsNeeded || isDocumentNeededStatus.isCodiceFiscaleNeeded || isDocumentNeededStatus.isPRDAndFSGNeeded) && (
@@ -204,6 +206,7 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
204206
setUploadError(error, directorsProofInputID);
205207
}}
206208
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
209+
maxFileSize={CONST.NON_USD_BANK_ACCOUNT.MAX_FILE_SIZE}
207210
/>
208211
<Text style={[styles.mutedTextLabel, styles.mt6]}>{translate('signerInfoStep.proofOfDirectorsDescription')}</Text>
209212
{(isDocumentNeededStatus.isCodiceFiscaleNeeded || isDocumentNeededStatus.isPRDAndFSGNeeded) && <View style={[styles.sectionDividerLine, styles.mt6, styles.mb6]} />}
@@ -229,6 +232,7 @@ function UploadDocuments({onNext, isEditing}: UploadDocumentsProps) {
229232
setUploadError(error, codiceFiscaleInputID);
230233
}}
231234
fileLimit={CONST.NON_USD_BANK_ACCOUNT.FILE_LIMIT}
235+
maxFileSize={CONST.NON_USD_BANK_ACCOUNT.MAX_FILE_SIZE}
232236
/>
233237
<Text style={[styles.mutedTextLabel, styles.mt6]}>{translate('signerInfoStep.codiceFiscaleDescription')}</Text>
234238
{isDocumentNeededStatus.isPRDAndFSGNeeded && <View style={[styles.sectionDividerLine, styles.mt6, styles.mb6]} />}

0 commit comments

Comments
 (0)