以nodejs的asynchronous模式使用Multer上传function

我需要使用callback进行Multer Midware函数(“上传”)的转换,以使用promise作为asynchronous模式。

我试图在承诺中转换上传function。

发送到服务器的图像像以前一样继续保存,但是我的代码会抛出一个错误:

(node:3568) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): undefined (node:3568) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 

当我执行function

 var resp=await uploadAsync(req, res); 

我究竟做错了什么?

//服务器代码

 'use strict'; const express = require('express'); const router = express.Router(); const pool = require('./pool'); // my database pool module, using promise-mysql const Errors = require('./mysql_errors'); // my collection of custom exceptions const HttpStatus = require('http-status-codes'); var path = require('path') var fs = require('fs') const fileDir='./public/images/uploads' //imagens const multer = require('multer'); const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, fileDir) }, filename: function (req, file, cb) { cb(null, Date.now() + '-' + file.originalname); } }) const upload = multer({ storage: storage}).single('foto'); function uploadAsync(req,res){ return new Promise(function(resolve,reject){ upload(req,res,function(err){ if(err !== null) return reject(err); resolve(); }); }); } router.post('/foto/:id',uploadAsync, async function(req,res,next){ try{ var resp=await uploadAsync(req, res); }catch(err) { return res.status(500).send({ success:false, message: 'Erro', results:{} }); // 404 } }); module.exports=router;