question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multer options neglected when using MulterModule like on the docs.

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ExpDev07commented, Sep 6, 2019

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 the AppModule 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.

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?

3reactions
brianmcdcommented, May 13, 2019

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 the AppModule 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found