Skip to content

Instantly share code, notes, and snippets.

@tranchausky
Last active September 12, 2023 16:10
Show Gist options
  • Save tranchausky/3c5219a16b57564994102f607b36eb06 to your computer and use it in GitHub Desktop.
Save tranchausky/3c5219a16b57564994102f607b36eb06 to your computer and use it in GitHub Desktop.
javascript base64 image from readyfile
//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