我正在使用express-fileupload上传图像,以下是我上传文件的代码,它位于imageUpload.js文件中。
exports.driverImages = function (req, imageFirstName) {
if (!req) {
console.log('no req')
return new Promise(resolve => setTimeout( () => resolve(false),
1000));
} else {
let id = new mongoose.Types.ObjectId(imageFirstName);
console.log(id);
Driver.findById(id)
.exec(function (err, result) {
if (err) {
console.log('err')
return new Promise(resolve => setTimeout( () => resolve(false), 1000));
} else {
if (result !== null) {
return new Promise(resolve => setTimeout( () => resolve(true), 1000));
} else {
console.log('no driver');
return false;
}
}
});
}
};
我正在从driverController.js调用此函数,如下所示,
async function imageAsync(files, id) {
let data = await imageUpload.driverImages(files, id);
console.log('imgAsy')
return data;
}
我的问题是,尽管我在driverImages()处有返回值,但它始终返回未定义的返回值。请帮忙!。