Skip to content
Advertisement

Having trouble getting a Base64 string from FileReader

I’m attempting to pass a file from an file input field’s file list through FileReader and get the Base64 string to pass to the server via axios. The FileReader’s onload function seems to get the string, but it evidently loses the string before it is returned. So, the value is undefined when I try to append it to the form data.

I’m told this is an asynchronous function, but I’m not sure where to await the promise. Can someone tell me what I’m doing wrong here?

JavaScript

Advertisement

Answer

You have to create the promise yourself

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