feat(api): add per-type file size limits and 413 responses for media uploads
- FileValidationPipe now supports maxSizeByMimeType for per-MIME-type size limits - Images: max 10MB, Video (MP4): max 100MB - Oversized files return 413 Payload Too Large instead of 400 Bad Request - MIME type validation runs before size check for clearer error messages - Multer module limit raised to 100MB (per-type enforcement in pipe) - Added 413 ApiResponse to Swagger docs on upload endpoint - Added comprehensive unit tests for FileValidationPipe (16 test cases) Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -169,13 +169,17 @@ export class ListingsController {
|
||||
@ApiParam({ name: 'id', description: 'Listing UUID' })
|
||||
@ApiResponse({ status: 201, description: 'Media uploaded successfully' })
|
||||
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
||||
@ApiResponse({ status: 413, description: 'File too large (images: max 10MB, video: max 100MB)' })
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
@Post(':id/media')
|
||||
async uploadMedia(
|
||||
@Param('id') id: string,
|
||||
@UploadedFile(new FileValidationPipe({
|
||||
maxSizeBytes: 10 * 1024 * 1024, // 10 MB
|
||||
maxSizeBytes: 10 * 1024 * 1024, // 10 MB default for images
|
||||
maxSizeByMimeType: {
|
||||
'video/mp4': 100 * 1024 * 1024, // 100 MB for video
|
||||
},
|
||||
allowedMimeTypes: ['image/jpeg', 'image/png', 'image/webp', 'video/mp4'],
|
||||
}))
|
||||
file: ValidatedFile,
|
||||
|
||||
Reference in New Issue
Block a user