How can I convert an image into Base64 string using JavaScript?
base64, javascript
Solution
You can use the HTML5 `<canvas>` for it:
Create a canvas, load your image into it and then use `toDataURL()` to get the Base64 representation (actually, it's a `data:` URL, but it contains the Base64-encoded image).
Problem
I need to convert my image to a Base64 string so that I can send my image to a server. Is there any JavaScript file for this? Else, how can I convert it?
Related problems
- Get image data URL in JavaScript?
- Image convert to Base64
- How does the 'Access-Control-Allow-Origin' header work?
- Why were Javascript `atob()` and `btoa()` named like that?
- Base64 String to byte[] in java
- How can you encode a string to Base64 in JavaScript?
- Convert an image to canvas that is already loaded