1
我試圖用承諾和AWS JS SDK第一次,我收到以下錯誤DeprecationWarning:調用無回調異步函數已不再使用AWS JS SDK
DeprecationWarning:調用異步函數不回撥已棄用。
我在下面提供了一個堆棧跟蹤。它似乎錯誤發生在我嘗試使用fs.unlink
刪除我下載的文件。
exports.generate = function (req, res) {
if (typeof Promise === 'undefined') {
AWS.config.setPromisesDependency(require('bluebird'));
}
var removeBatch = function removeBatch(files) {
return Promise.all(files.map(function(file) {
return fs.unlink(file.key);
}));
};
var getBatch = function getBatch(files) {
return Promise.all(files.map(function(file) {
var params = {
Bucket: 'my-bucket',
Key: file.key
};
return app.s3.getObject(params).createReadStream().pipe(file.stream);
}));
};
var fileNames = ['Original 106fm Logo #268390.jpg', 'test.jpg'];
var files = fileNames.map(function(fileName) {
return {
key: fileName,
stream: fs.createWriteStream(fileName)
};
});
getBatch(files)
.then(removeBatch.bind(null, files))
.catch(console.error.bind(console));
}
這是堆棧跟蹤
(node:63311) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.
at makeCallback (fs.js:127:12)
at Object.fs.unlink (fs.js:1054:14)
at /src/splash.js:12:7
at Array.map (native)
at removeBatch (/src/splash.js:11:28)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:208:7)
如何正確地從我的removeBatch
方法返回一個承諾?
感謝@rsp,多麼出色答卷! –