Multer options neglected when using MulterModule like on the docs.
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I followed the File Upload async configuration documentation
Expected behavior
Multer options should work, uploading a file exceeding the limit should not work, and I should see the log from fileFilter
function each time I do an upload.
Minimal reproduction of the problem with instructions
The app module app.module.ts
:
@Module({
imports: [
MulterModule.registerAsync({
imports: [ConfigModule],
useFactory: async (config: ConfigService) => ({
fileFilter: (req, file, cb) => {
console.log('********************', config.get('FILE_SIZE_LIMIT'));
cb(null, true);
},
limits: {
fileSize: config.get('FILE_SIZE_LIMIT'),
},
}),
inject: [ConfigService],
}),
]
})
The controller controller.ts
@Controller('upload')
export class FilesController {
constructor(private readonly config: ConfigService) {}
@Post()
@UseInterceptors(FileInterceptor('file'))
upload(@UploadedFile() file) {
console.log(file);
return 'Okay';
}
}
When having multer options as the second argument of FileInterceptor
everything works fine, but when using MulterModule
just like on the docs, the options are neglected.
Environment
Nest version: 6.1.1
For Tooling issues:
- Node version: 10.15.3
- Platform: Linux
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
File upload | NestJS - A progressive Node.js framework
When you need to set MulterModule options asynchronously instead of statically, use the registerAsync() method. As with most dynamic modules, Nest provides ...
Read more >req files and req body are undefined when using multer and ...
It's undefined because you're accessing request's undefined properties req.new_files and req.bodyData , so change console.log('req files--', ...
Read more >Nestjs file uploading using Multer - Gabriel Tanner
Let's start by importing the MulterModule in your AppModule so you can use Multer in your other files. import { Module } from...
Read more >Express multer middleware
Multer is a node.js middleware for handling multipart/form-data , which is primarily used for uploading files. It is written on top of busboy...
Read more >Uploading Files Using Multer in a Node.js Application
In this article, we will see how to use Multer to handle multipart/form-data using ... Your HTML code should look something like this:....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can we get an update on this? I just ran into it as an issue. Seems like this is something that you’d only want to define at the AppModule like with database and not need to copy into every module where you’ll use multer?
I ran into a similar issue. I was trying to register multer in
AppModule
, but expected the settings there to be used in a feature module. The multer options get consumed while the feature module is being created, so anything set in theAppModule
is ignored. Not sure if this is by design or a bug, but moving the multer module import to the feature module fixed it for me.