How to convert file to base64 in JavaScript?

前端 未结 7 1949
醉话见心
醉话见心 2020-11-22 06:34

Now I\'m getting File object by this line:

file = document.querySelector(\'#files > input[type=\"file\"]\').files[0]

I need to send thi

7条回答
  •  太阳男子
    2020-11-22 06:47

    onInputChange(evt) {
        var tgt = evt.target || window.event.srcElement,
        files = tgt.files;
        if (FileReader && files && files.length) {
            var fr = new FileReader();
            fr.onload = function () {
                var base64 = fr.result;
                debugger;
            }
            fr.readAsDataURL(files[0]);
        }
    }
    

提交回复
热议问题