Last active
September 19, 2017 14:02
-
-
Save vsimko/6df81892c8f4e44df6e210f6ff3acc1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // sending-a-file-as-multipart-through-xmlhttprequest | |
| https://stackoverflow.com/questions/9395911/sending-a-file-as-multipart-through-xmlhttprequest | |
| // change the id `USE-YOUR-ID` | |
| const img = document.getElementById('USE-YOUR-ID'); | |
| // extracts image data from <img> element through canvas | |
| const canvas = document.createElement('canvas'); | |
| const context = canvas.getContext('2d'); | |
| canvas.width = img.width; | |
| canvas.height = img.height; | |
| context.drawImage(img, 0, 0 ); | |
| const myData = context.getImageData(0, 0, img.width, img.height); | |
| // this converts the image into base64 | |
| const str = btoa(myData.data) | |
| console.log(str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment