Skip to content
Advertisement

‘await’ call doesn’t wait

My app is trying to upload files to S3. S3 upload works fine. The problem is that after imageUpload returns, in handleSubmit(), it claims that the return value for imageUpload() is undefined. I suspect that it has to do with async/await, which I’m not too familiar with. Can any expert explain what I’m missing?

JavaScript

Advertisement

Answer

You have to wrap your imageUpload code inside promise and then pass the data to resolve callback that you want to return, and if there is some error you pass them in reject callback, throwing error in asynchronous task can give unexpected behaviour, so use reject callback there.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement