我正在使用google-cloud-functions在将文件上传到Google云端存储时触发缩略图创建。
exports.generateThumbnail = functions.storage.object().onFinalize(async (object) => {
// Removed code not relevant to the problem
// Download file from bucket.
await file.download({destination: tempLocalFile});
const uploadPromises = sizes.map(async size => {
const tempLocalThumbfile = path.join(os.tmpdir(),thumbfilePath);
// Generate a thumbnail using Sharp.
await sharp(tempLocalFile).resize(width,height).toFile(tempLocalThumbfile);
console.log('Thumbnail created at',tempLocalThumbfile);
return thumbfile.getSignedUrl(config);
});
// Get the Signed URLs for the original image.
const results = await Promise.all([
uploadPromises,file.getSignedUrl(config),]);
console.log(results[0]);
});
我希望最后一个console.log输出的是大小为4的数组,其中每个元素都包含getSignedurl()函数的回调。相反,我现在每次得到的是大小为4的数组,其中所有元素都是promise。
由于我已经在等待Promise.all(),所以我做错了什么才能导致这个问题?