I'm trying to upload multiple files to a Google Cloud Storage bucket using NodeJS. I want all files to be uploaded before continuing. I tried several approaches but I can't seem to get it right.
const jpegImages = await fs.readdir(jpegFolder);
console.log('start uploading');
await jpegImages.forEach(async fileName => {
await bucket.upload(
path.join(jpegFolder, fileName),
{destination: fileName}
).then( () => {
console.log(fileName + ' uploaded');
})
})
console.log('finished uploading');
This gives me the following output, which is not what I expect. Why is the 'finished uploading' log not executed after uploading the files?
start uploading
finished uploading
image1.jpeg uploaded
image2.jpeg uploaded
image3.jpeg uploaded