I want to create a file uploader section. I put the following code in order: app.module.ts :
imports: [
MulterModule.register({
dest: './uploads',
}),
]
files.controller.ts :
@Post('upload')
@UseInterceptors(FileInterceptor('file'))
uploadFile(@UploadedFile() file) {
console.log(file);
}
I will not receive any errors after sending the file, but the file will not be uploaded:
{
fieldname: 'file',
originalname: 'xsmn4d0c_thumb3.jpg',
encoding: '7bit',
mimetype: 'image/jpeg',
buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 60 00 60 00 00 ff db 00 43 00 08 06 06 07 06 05 08 07 07 07 09 09 08 0a 0c 14 0d 0c 0b 0b 0c 19 12 13 0f
... 10640 more bytes>,
size: 10690
}
but use this code on app.controller.ts , upload successfuly: files.controller.ts :
@Post('upload')
@UseInterceptors(FileInterceptor('file'))
uploadFile(@UploadedFile() file) {
console.log(file);
}
{
fieldname: 'file',
originalname: 'xsmn4d0c_thumb3.jpg',
encoding: '7bit',
mimetype: 'image/jpeg',
destination: './upload',
filename: '651c4567aeadc02e63c449feeac158fa',
path: 'upload/651c4567aeadc02e63c449feeac158fa',
size: 10690
}
what is deferent ?
You need the MulterModule
in your FilesModule
and not just in AppModule
as MulterModule
is not @Global()
so adding it only to AppModule
means that AppModule
gets the config to work with the dest
and FilesModule
does not