I'm using google-cloud-functions to trigger thumbnail creation on uploading a file to Google cloud storage.
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]);
});
What I would expect the last console.log to output is an array of size 4, where each element contains the callback of the getSignedurl() function. Instead what I now get each time, is an array of size 4 where all elements are promises.
Since I'm already awaiting the Promise.all() what have I done wrong to end up with this issue?