Added log for unsupported Mime type

This commit is contained in:
Alex Tran 2022-12-22 21:24:28 -06:00
parent d3bc92c3f8
commit ab56ab9b27
No known key found for this signature in database
GPG Key ID: E4954BC787B85C8A

View File

@ -1,5 +1,5 @@
import { APP_UPLOAD_LOCATION } from '@app/common/constants';
import { BadRequestException, UnauthorizedException } from '@nestjs/common';
import { BadRequestException, Logger, UnauthorizedException } from '@nestjs/common';
import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
import { randomUUID } from 'crypto';
import { Request } from 'express';
@ -9,6 +9,8 @@ import { extname, join } from 'path';
import sanitize from 'sanitize-filename';
import { patchFormData } from '../utils/path-form-data.util';
const logger = new Logger('AssetUploadConfig');
export const assetUploadOption: MulterOptions = {
fileFilter,
storage: diskStorage({
@ -30,6 +32,7 @@ function fileFilter(req: Request, file: any, cb: any) {
) {
cb(null, true);
} else {
logger.error(`Unsupported file type ${extname(file.originalname)} file MIME type ${file.mimetype}`);
cb(new BadRequestException(`Unsupported file type ${extname(file.originalname)}`), false);
}
}