SHARE
TWEET

Untitled

a guest Jul 24th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function readFile(input) {
  2.  
  3.     if (input.files && input.files[0]) {
  4.  
  5.         var reader = new FileReader();
  6.  
  7.  
  8.  
  9.         reader.onload = function (e) {
  10.  
  11.             var filePreview = document.createElement('img');
  12.  
  13.             filePreview.id = 'file-preview';
  14.  
  15.             //e.target.result contents the base64 data from the image uploaded
  16.  
  17.             filePreview.src = e.target.result;
  18.  
  19.             console.log(e.target.result);
  20.  
  21.  
  22.  
  23.             var previewZone = document.getElementById('file-preview-zone');
  24.  
  25.             previewZone.appendChild(filePreview);
  26.  
  27.         }
  28.  
  29.  
  30.  
  31.         reader.readAsDataURL(input.files[0]);
  32.  
  33.     }
  34.  
  35. }
  36.  
  37.  
  38.  
  39. var fileUpload = document.getElementById('file-upload');
  40.  
  41. fileUpload.onchange = function (e) {
  42.  
  43.     readFile(e.srcElement);
  44.  
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top