Skip to content

Instantly share code, notes, and snippets.

@alexcorvi
Last active June 27, 2016 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcorvi/493acf5d7ba619a0867ff4ac5c9ad309 to your computer and use it in GitHub Desktop.
Save alexcorvi/493acf5d7ba619a0867ff4ac5c9ad309 to your computer and use it in GitHub Desktop.
$.file2URI = function (obj) {
if (obj.el.files && obj.el.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
obj.success(e.target.result);
}
reader.readAsDataURL(obj.el.files[0]);
}
else {
obj.error();
}
}
/**
* Usage: pass an object like this one below
**/
$.file2URI({
el:docuemnt.getElementById("#input"),
success:function(res) {
docuemnt.write(res);
}
error:alert("Your browser doens't support data uris");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment