我正在尝试使用异步实现序列中的promise并导出此函数。但是我收到了语法错误
exports.editImage = function(sourceBucket, sourceKey, options) {
const imagePath = await downloadImage({
Bucket: sourceBucket,
Key: sourceKey,
});
const info = await imageInfo(imagePath);
const imageBuffer = await resizeImage(imagePath, info, options);
const result = await uploadImage(imageBuffer, info, options);
return result;
};
错误
' const imagePath =等待downloadImage({', ' ^^^^^^^^^^^^^&#39 ;, '',
' SyntaxError:意外的标识符',`
我有什么遗失的吗?
答案 0 :(得分:2)
await
只能在async
函数中使用。
将您的功能设置为异步:
exports.editImage = async function(sourceBucket, sourceKey, options) {
答案 1 :(得分:1)
你忘了异步:
exports.editImage = async function(sourceBucket, sourceKey, options) {