I want to upload file and use dto to validate other things in nest
but when send request by post man I get bad request (that’s from dto ) and when I remove send file everything works fine
This is my controller :
@Post()
@UseInterceptors(FileInterceptor('image', SaveImageToStorage))
// @UploadedFile() file: Express.Multer.File ,
create(
@Body() createTicketDto: CreateTicketDto,
@Request() req,
) {
try {
// console.log(image);
console.log(createTicketDto);
// return this.ticketService.create(createTicketDto) ;
} catch (error) {
console.log(error);
}
}
and this is the error after sending my request from postman :
{
"message": "Bad Request",
"statusCode": 400
}
I cant upload image and get all files !
I need an answer why this is happening
2
Answers
Is it possible to have a screen of your postman request ?
First of all, check your imports, maybe problem in them.
FileInterceptor
import from "@nestjs/platform-express",UseInterceptors
from "@nestjs/common".Remove file from your dto, if it exist. File you are going to get using this way:
@UploadedFile() file: Express.Multer.File
. Use DTO for other things.Your
SaveImageToStorage
gotta look like this:import {diskStorage} from "multer";
and
import {extname} from "path";