import { MulterModule } from '@nestjs/platform-express';
import * as fs from 'fs';
import { diskStorage } from 'multer';
import * as path from 'path';
...
MulterModule.registerAsync({
imports: [SharedModule],
useFactory: async (configService: ConfigService) => ({
storage: diskStorage({
destination: configService.config.dialerFilePath.upload,
filename: (req, file, callback) => {
callback(null, file.originalname);
},
}),
fileFilter: (req, file, callback) => {
if (fs.existsSync(path.join(configService.config.dialerFilePath.upload, file.originalname))) {
callback(new NotAcceptableException(`File ${file.originalname} is already uploaded!`));
} else {
callback(null, true);
}
},
}),
inject: [ConfigService],
}),