Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 等待承诺已创建Array.map返回<;待定>;_Javascript_Node.js_Asynchronous_Google Cloud Functions_Es6 Promise - Fatal编程技术网

Javascript 等待承诺已创建Array.map返回<;待定>;

Javascript 等待承诺已创建Array.map返回<;待定>;,javascript,node.js,asynchronous,google-cloud-functions,es6-promise,Javascript,Node.js,Asynchronous,Google Cloud Functions,Es6 Promise,我使用谷歌云函数在上传文件到谷歌云存储时触发缩略图创建 exports.generateThumbnail = functions.storage.object().onFinalize(async (object) => { // Removed code not relevant to the problem // Download file from bucket. await file.download({destination: tempLoca

我使用谷歌云函数在上传文件到谷歌云存储时触发缩略图创建

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的数组,其中所有元素都是

因为我已经在等待承诺了。all()我做错了什么,导致了这个问题?

尝试
承诺中的
上传承诺。all

const results = await Promise.all([
   ...uploadPromises,
   file.getSignedUrl(config),
]);
问题是
uploadPromises
已经是一个数组,而您将它作为另一个数组的元素传递。通过使用,可以将
uploadPromises
数组展开到其元素中