File tree Expand file tree Collapse file tree
apps/api/src/evidence-forms Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -196,19 +196,17 @@ export class EvidenceFormsService {
196196 ) ;
197197 }
198198
199- const base64Pattern = / ^ [ A - Z a - z 0 - 9 + / ] + = { 0 , 2 } $ / ;
200- if ( ! base64Pattern . test ( normalized ) ) {
201- throw new BadRequestException (
202- 'Invalid file data. Expected base64 string.' ,
203- ) ;
204- }
199+ try {
200+ const fileBuffer = Buffer . from ( normalized , 'base64' ) ;
205201
206- const fileBuffer = Buffer . from ( normalized , 'base64' ) ;
207- if ( ! fileBuffer . length ) {
208- throw new BadRequestException ( 'File cannot be empty' ) ;
209- }
202+ if ( ! fileBuffer . length ) {
203+ throw new BadRequestException ( 'File cannot be empty.' ) ;
204+ }
210205
211- return fileBuffer ;
206+ return fileBuffer ;
207+ } catch {
208+ throw new BadRequestException ( 'Invalid file data. Expected base64 string.' ) ;
209+ }
212210 }
213211
214212 /**
You can’t perform that action at this time.
0 commit comments