Skip to content

Commit 0bbc73b

Browse files
authored
Merge pull request #2819 from trycompai/chas/upload-documents
CS-355 [Bug] - Internal server error when trying to upload png file to Network Diagram document in app
2 parents 043c70a + 35092d7 commit 0bbc73b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

apps/api/src/evidence-forms/evidence-forms.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,16 @@ export class EvidenceFormsService {
196196
);
197197
}
198198

199-
const base64Pattern = /^[A-Za-z0-9+/]+={0,2}$/;
200-
if (!base64Pattern.test(normalized)) {
199+
const fileBuffer = Buffer.from(normalized, 'base64');
200+
201+
if (fileBuffer.toString('base64') !== normalized) {
201202
throw new BadRequestException(
202203
'Invalid file data. Expected base64 string.',
203204
);
204205
}
205206

206-
const fileBuffer = Buffer.from(normalized, 'base64');
207207
if (!fileBuffer.length) {
208-
throw new BadRequestException('File cannot be empty');
208+
throw new BadRequestException('File cannot be empty.');
209209
}
210210

211211
return fileBuffer;

0 commit comments

Comments
 (0)