카테고리 없음
nestjs 파일업로드
i'm suna
2023. 12. 28. 08:21
파일 업로드
@ApiBody와 함께 데코레이터를 사용하여 특정 메소드에 대한 파일 업로드를 활성화할 수 있습니다 @ApiConsumes(). 다음은 파일 업로드 기술을 사용한 전체 예입니다 .
@UseInterceptors(FileInterceptor('file'))
@ApiConsumes('multipart/form-data')
@ApiBody({
description: 'List of cats',
type: FileUploadDto,
})
uploadFile(@UploadedFile() file) {}
여기서는 FileUploadDto다음과 같이 정의됩니다.
class FileUploadDto {
@ApiProperty({ type: 'string', format: 'binary' })
file: any;
}
여러 파일 업로드를 처리하려면 FilesUploadDto다음과 같이 정의할 수 있습니다.
class FilesUploadDto {
@ApiProperty({ type: 'array', items: { type: 'string', format: 'binary' } })
files: any[];
}