不确定异步中的解决方案,但可以使用如下回调:
exports.uploadFile = async function (cb) {
fs.readFile('./text.txt', function (err, contents) {
if (err) {
console.log('Error: ', err);
}
uploadFile(contents,cb);
});
} ;
async function uploadFile(fileCont,cb) {
let dbx = new Dropbox({ accessToken: APP_KEY });
await dbx.filesUpload({ path: '/basic4.txt', contents: fileCont })
.then(function (response) {
console.log( response);
cb(response);//Pass response in callback
})
.catch(function (err) {
console.log(err);
});
}
DriveService.uploadFile(function(success) {//this callback will be called from async
return res.status(200).json({success:true,data:success,message:'list of files recived')
})
.catch((error)=>{
return res.status(400).json({success:false,data:{},message:error.message});
})