上传文件转成base64

通过FileReader把上传的文件转换成base64 ,可以用于上传前预览

 <input type="file" class="uploader" accept="image/*"  multiple>
 $(document).on('change','.uploader',function(){
            // 获取当前选中的文件

            let file = this.files;  //读取文件

            let reader = new FileReader();

            reader.readAsDataURL(file[0]);

            reader.onload = function() {

                let result = this.result;   //result为data url的形式
                console.log(result);
            }

        })

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注




Enter Captcha Here :