Skip to content

Instantly share code, notes, and snippets.

@christophfink
Created October 20, 2016 11:14
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 christophfink/cb5b2959dc64aad77ab5e6de66f67263 to your computer and use it in GitHub Desktop.
Save christophfink/cb5b2959dc64aad77ab5e6de66f67263 to your computer and use it in GitHub Desktop.
$("input:file").change(function(e){
var input=e.target;
// create a new FileReader object, and …
var reader=new FileReader();
// … tell it what to do in case of it successfully loading the file
reader.onloadend=function(e){
var fileBase64=e.target.result;
$(input).siblings("input:text").first().val(fileBase64);
};
// … and have it load the file
reader.readAsDataURL(input.files[0]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment