Answers for "to to upload photo with js"

9

preview image file upload javascript

<input type="file" accept="image/*" onchange="loadFile(event)">
<img id="output"/>
<script>
  var loadFile = function(event) {
    var output = document.getElementById('output');
    output.src = URL.createObjectURL(event.target.files[0]);
    output.onload = function() {
      URL.revokeObjectURL(output.src) // free memory
    }
  };
</script>
Posted by: Guest on November-09-2020
0

how to paste image on upload js

document.addEventListener('paste', function(e){
  console.warn(e.clipboardData.items.length);
  for (var i = 0; i < e.clipboardData.items.length; i++) {
    var item = e.clipboardData.items[i];
    console.log('Item: ' + item.type);
    if (item.type.indexOf('image') != -1) {
      //item.
      console.log(item.getAsFile());
    } else {
      // ignore not images
      console.log('Discarding not image paste data', item);
    }
  }
});
Posted by: Guest on July-12-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language