I'm having an issue with getting the correct value returned with an async function. Here's the code . I'm getting the signedUrls after uploading an image and that works correctly, but it is getting to that line too late after the return. The value I want to return is "signedUrls[0]" but right now it is returning something different. I'm not sure what I'm missing to get it to return the correct value. Thanks so much!
var uploadedUrl = response.data.pipe(writeStream)
.on('finish', async () => {
console.log('Successfully uploaded image: ');
signedUrls = await file.getSignedUrl({
action: 'read',
expires: '03-09-2491'
});
console.log("signedUrls: ",signedUrls);
return signedUrls[0];
})
.on('error', () => {
console.log('Error uploading image');
return "";
});
console.log("uploadedURL: ",uploadedUrl);