Skip to content

Commit

Permalink
Merge pull request #369 from boostcampwm2023/BE-FixFileVali-#358
Browse files Browse the repository at this point in the history
[BE] 파일사이즈 검사 로직 수정
  • Loading branch information
namewhat99 authored Dec 6, 2023
2 parents 917ca27 + 9d47380 commit 55b7f7c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
6 changes: 1 addition & 5 deletions BE/src/post/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Express.Multer.File>,
@MultiPartBody(
'post_info',
Expand Down
3 changes: 2 additions & 1 deletion BE/src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion BE/src/utils/files.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 55b7f7c

Please sign in to comment.