Last active
September 12, 2023 16:10
-
-
Save tranchausky/3c5219a16b57564994102f607b36eb06 to your computer and use it in GitHub Desktop.
javascript base64 image from readyfile
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
| //https://stackoverflow.com/a/20513288 | |
| return dataURL.replace(/^data:image\/(png|jpg);base64,/, ""); | |
| $(document).ready(function(){ | |
| function readImage(input) { | |
| var FR= new FileReader(); | |
| FR.onload = function(e) { | |
| console.log(e.target.result); | |
| $.ajax({ | |
| url: 'https://api.imgur.com/3/image', | |
| type: 'post', | |
| headers: { | |
| Authorization: 'Client-ID 1111111111' | |
| }, | |
| data: { | |
| image: e.target.result.replace(/^data:image\/(png|jpg);base64,/, "") | |
| }, | |
| dataType: 'json', | |
| success: function(json) { | |
| console.log(json); | |
| }, | |
| error: function(json) { | |
| console.log(json); | |
| } | |
| }); | |
| }; | |
| FR.readAsDataURL( input ); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment