https://github.com/nestjs/nest/commit/f210ebca2fddecef6b235547498b46fe76b3b9e5
I use Multer for File Upload. Before v.6.3.1 I imported MulterModule in AppModule only, it worked globally. After v.6.3.1, it works not globally anymore, at least, it's options (destination) is not gobally. I need to import MulterModule in any Module where I upload files now.
https://github.com/hellokvn/nest-multer
Upload "file" to: PUT http://localhost:3000
file path is correct (see console log)
Upload "file" to: PUT http://localhost:3000/lorem
file path is incorrect (see console log)
I expect to import MulterModule only once, as long it's inside AppModule. Not sure, if my expectation is like it really should be. If I am wrong, it would be nice to know how I can use MulterModule globally.
Nest version: 6.3.1
For Tooling issues:
I fixed it by using .forRoot();
https://github.com/hellokvn/nest-multer/commit/8465fdf6b75006cd0700c100e9a84f46c7282415
@hellokvn thanks so much for that! How did you figure this one out?
It was never supposed to work globally.
I expect to import MulterModule only once, as long it's inside AppModule. Not sure, if my expectation is like it really should be. If I am wrong, it would be nice to know how I can use MulterModule globally.
Use @Global() decorator
@hellokvn
How did you resolve this?
All links on this issue is unavailable now :(
Here i have the same problem
Use @Global() decorator
If it doesn't work, please link me a repository. I will try to fix it then.
Sorry about that, i found the solution:
After put @Global and configure i need includes MulterModule on exports in app.module:
@Global()
@Module({
imports: [
MulterModule.register({
storage: diskStorage({
destination: './uploads',
filename: (req, file, cb) => {
const randomName = Array(32).fill(null).map(() => (Math.round(Math.random() * 16)).toString(16)).join('')
return cb(null, `${randomName}${extname(file.originalname)}`)
}
})
}),
...
],
controllers: [AppController],
providers: [AppService],
exports: [MulterModule]
})
export class AppModule { }
commented here
Great! Personally, I would recommend to put the MulterModule into some ConfigModule which you should make global and import it into AppModule usually. That's how I do it.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.