Skip to main content

image upload without multer or any of package

 



<script type="text/javascript" >
    function readURL(res) {
        if (res) {
            var reader = new FileReader();
            reader.onload = function (e) {
                console.log(e.target.result);
                $('#blah').attr('src', e.target.result);
            }
            reader.readAsDataURL(res);
        }
    }

  //this is for image preview while uploadding

function view(){
  const file = document.getElementById('imgInp').files[0];
  console.log(file);
//this is image compress

  imageConversion.compressAccurately(file,100).then(res=>{
    //The res in the promise is a compressed Blob type (which can be treated as a File type) file;
    console.log(res);
    readURL(res)
  })
}

imageConversion link
<script src="https://cdn.jsdelivr.net/gh/WangYuLue/image-conversion
/build/conversion.js"></script>

Comments

Popular posts from this blog

ajeet

 

JavaScript Hash function

 java Script hash  code for genrating sam number as  function hashCode ( string ) { let hash = 0 ; if (string. length == 0 ) { return hash; } for ( let i = 0 ; i < string. length ; i++) { let char = string. charCodeAt (i); hash = ((hash<< 5 )-hash)+char; hash = hash & hash; } return hash; } let input = document . querySelector ( "#input" ) let output = document . querySelector ( "#output" ) input. addEventListener ( "keyup" , () => { output. value = hashCode (input. value ) }) html < p > Enter text here </ p > < input type = "text" id = "input" > < p > 'Random' number outputted here </ p > < input type = "text" disabled = "disabled" value = "" id = "output" >