Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how does URL.createObjectURl differ from fileReader

const fileSelect = document.getElementById("fileSelect"),
    fileElem = document.getElementById("fileElem"),
    fileList = document.getElementById("fileList");

fileSelect.addEventListener("click", function (e) {
  if (fileElem) {
    fileElem.click();
  }
  e.preventDefault(); // prevent navigation to "#"
}, false);

fileElem.addEventListener("change", handleFiles, false); 

function handleFiles() {
  if (!this.files.length) {
    fileList.innerHTML = "<p>No files selected!</p>";
  } else {
    fileList.innerHTML = "";
    const list = document.createElement("ul");
    fileList.appendChild(list);
    for (let i = 0; i < this.files.length; i++) {
      const li = document.createElement("li");
      list.appendChild(li);
      
      const img = document.createElement("img");
      img.src = URL.createObjectURL(this.files[i]);
      img.height = 60;
      img.onload = function() {
        URL.revokeObjectURL(this.src);
      }
      li.appendChild(img);
      const info = document.createElement("span");
      info.innerHTML = this.files[i].name + ": " + this.files[i].size + " bytes";
      li.appendChild(info);
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: att asm jmp 
Javascript :: external javascript files can be cached 
Javascript :: srcset vue 
Javascript :: wordpress apostrophe problem in javascript 
Javascript :: how to send array to js file in wplms 
Javascript :: quasar composition api $q 
Javascript :: imagebackground with input inot avoiding react native 
Javascript :: how add all json files to one json file in command prompt 
Javascript :: auto increment string in javascript 
Javascript :: javascript Bingo add called number to a list 
Javascript :: create react element with string 
Javascript :: moment add days non destructive 
Javascript :: how to set Json node in java 
Javascript :: backbone model save without validation 
Javascript :: useEffectOnce 
Javascript :: Angular watching for changes in $http.pendingRequests from directive 
Javascript :: pick equivalen in es6 
Javascript :: javascript 2 decimal float array elements 
Javascript :: Cypress.currentTest 
Javascript :: HTML5 Accesskey Attribute: you may not need JavaScript to add Keyboard Shortcuts 
Javascript :: event listener function called parameters 
Javascript :: angular add debounce time before putting valu in subject next 
Javascript :: activejs 
Javascript :: react createElement interactive button 
Javascript :: javascript compute heading on too points 
Javascript :: apex express 18 forgot password 
Javascript :: react hooks simple projects 
Javascript :: node js reuire json shows onject 
Javascript :: send props from one component to another on button click 
Javascript :: js resize div with mouse 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =