I have a register controller that also includes a file upload however the body of the request is always unserialized. I do not know how to resolve this.
@Post('register')
@UseInterceptors(
FileInterceptor('profile_picture', {
storage: diskStorage({
destination: './uploads',
filename: (req, file, callback) => {
const ext = extname(file.originalname);
const filename = `${req.session.username}-${Date.now()}${ext}`;
callback(null, filename);
}
})
})
)
async register(
@Body() body: CreateUserDto,
@Req() req: Request,
@UploadedFile() profile_picture?: Express.Multer.File
) {
return await this.authService.register(body, req, profile_picture);
}
I tried to do JSON.parse(body) but kept getting the error TypeError: Cannot convert object to primitive value. I'm not sure if I want to split this into separate controllers for uploading the file and creating the user.