#Multipart: Unexpected end of form error

11 messages · Page 1 of 1 (latest)

kind rivet
#

`@Post()
@Roles('USER', 'ADMIN')
@ApiConsumes('multipart/form-data')
@ApiBody({
description: 'Upload file',
type: 'object',
required: true,
})
@UseInterceptors(FileInterceptor('file'))
async uploadFile(
@UploadedFile(
new ParseFilePipe({
validators: [
new FileTypeValidator({ fileType: '.(png|jpeg|jpg)' }),
new MaxFileSizeValidator({ maxSize: 1024 * 1024 * 4 }),
],
}),
)
file: Express.Multer.File,
) {
console.log(file); // You can check the file object in the console
// await this.uploadService.uploadToFile(file);
return { message: 'File uploaded successfully' };
}

how do i resolve this error, this is the way it done in the docs for uploading images for example yet it is not working

merry warren
#

How do you send the file?

kind rivet
#

it is an image in postman i choose form-data and , set the ket as file and attach the image

merry warren
#

Hmm, postman should set the headers properly

kind rivet
#

yes true

#

so there is nth erong with the code ?

merry warren
#

Usually that error means there's something wrong with the request

kind rivet
#

and for this kinda of requests what important headers should be included ?
i have Content-Type set correctly

merry warren
#

content-type and multip[art boundary headers which are usually automatically calculated'

kind rivet
#

yes they are, but i mean is there a specific header that i need to set ?

merry warren
#

Most of the time what's necessary is set. You shouldn't need to set anything