前端文件上傳 獲取文件大小 獲取圖片寬高


<input type="file" multiple accept="image/*" id="input" >
    inputElement.addEventListener("change", function () {
        const fileList = this.files; /* this -》 當前dom         */
        console.log(fileList)
        var reader = new FileReader();
        reader.onload = function (e) {
            console.log(e)
            /*獲取圖片base64*/
            let src=e.target.result;
            img.src=src;
            img.onload=function (e) {
                // console.log(e)

            };
            /*獲取圖片blob*/
            var objectURL = window.URL.createObjectURL(fileList[0]);
            console.log('objectURL',objectURL)

            // window.URL.revokeObjectURL(objectURL);//文檔關閉會自動清除內存 也可手動關閉
        }
        reader.readAsDataURL(fileList[0]);
    }, false);

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM