我想在获取req.body之后重命名文件,但在读取正文之前先考虑文件的操作。
因此,我必须在接收正文之后调用multer(需要包装函数),但是我不知道该怎么做,因为在示例中,巢使用拦截器来调用multer,然后传递@UploadedFiles(): image
参数。 / p>
我该如何在Post装饰器中调用multer并传入multer req.body,然后传递返回的图像?
const storage = {
storage: diskStorage({
destination: (req, file, callback) => {
const user = req.query.email;
const appName = req.query.appName;
const path = `./src/View/images/${user}/${appName}/${file.fieldname}`;
if (!fs.existsSync(path)) {
mkDirByPathSync(path);
}
callback(null, path);
},
filename: (req, file, callback) => {
return callback(null, file.originalname);
},
}),
};
@Post('/generateTemplate')
@UseInterceptors(FileFieldsInterceptor([
{ name: 'appLogo', maxCount: 1 },
{ name: 'iconSmallPWA', maxCount: 1 },
{ name: 'iconMiddlePWA', maxCount: 1 },
{ name: 'usersAvatars', maxCount: 20 },
{ name: 'screenshots', maxCount: 20 },
], storage ))
receiveData(@UploadedFiles() images, @Body() fileDto: any, @Query() urlQuery: QueryInterface) {
this.formatDataService.formatReceivedData(fileDto.createAppForm, urlQuery.email);
this.filesService.formatReceivedFiles(images);
this.appService.generateHtml();
return 'ololo';
}