Skip to content
Advertisement

How to convert file to base64 in JavaScript?

UPD TypeScript version is also available in answers

Now I’m getting File object by this line:

JavaScript

I need to send this file via json in base 64. What should I do to convert it to base64 string?

Advertisement

Answer

Modern ES6 way (async/await)

JavaScript

UPD:

If you want to catch errors

JavaScript
Advertisement