diff --git a/BE/src/post/post.controller.ts b/BE/src/post/post.controller.ts index c4d2753..635911f 100644 --- a/BE/src/post/post.controller.ts +++ b/BE/src/post/post.controller.ts @@ -68,11 +68,7 @@ export class PostController { @UseInterceptors(FilesInterceptor('image', 12)) async postModify( @Param('id') id: number, - @UploadedFiles( - new ParseFilePipe({ - validators: [new MaxFileSizeValidator({ maxSize: 1024 * 1024 * 20 })], - }), - ) + @UploadedFiles(new FileSizeValidator()) files: Array, @MultiPartBody( 'post_info', diff --git a/BE/src/users/users.controller.ts b/BE/src/users/users.controller.ts index 179cd25..627df61 100644 --- a/BE/src/users/users.controller.ts +++ b/BE/src/users/users.controller.ts @@ -21,6 +21,7 @@ import { MultiPartBody } from 'src/utils/multiPartBody.decorator'; import { UpdateUsersDto } from './usersUpdate.dto'; import { AuthGuard } from 'src/utils/auth.guard'; import { UserHash } from '../utils/auth.decorator'; +import { FileSizeValidator } from '../utils/files.validator'; @Controller('users') @UseGuards(AuthGuard) @@ -70,7 +71,7 @@ export class UsersController { async usersModify( @Param('id') id: string, @MultiPartBody('profile') body: UpdateUsersDto, - @UploadedFile() file: Express.Multer.File, + @UploadedFile(new FileSizeValidator()) file: Express.Multer.File, @UserHash() userId, ) { await this.usersService.updateUserById(id, body, file, userId); diff --git a/BE/src/utils/files.validator.ts b/BE/src/utils/files.validator.ts index e920740..a2b2332 100644 --- a/BE/src/utils/files.validator.ts +++ b/BE/src/utils/files.validator.ts @@ -8,7 +8,7 @@ import { @Injectable() export class FileSizeValidator implements PipeTransform { transform(value: any, metadata: ArgumentMetadata): any { - if (value.length === 0) { + if (value === undefined || value.length === 0) { return value; } const maxSize = 1024 * 1024 * 20;