上传图片转base64,报错

报错:ERROR TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.

这是用ionic写的


\\xx.html

<input type="file" (change)="selectImage(this.files)" accept="image/jpeg,image/png,image/jpg">

\\xx.ts

selectImage(file){

      var reader = new FileReader();

      reader.onload = function(file){

        // console.log(evt.currentTarget)

      }

      reader.readAsDataURL(file);

      console.log(reader.readAsDataURL(file));  

  }

https://img2.mukewang.com/5ca316740001a26d08000320.jpg

慕哥9229398
浏览 2681回答 3
3回答

米脂

selectImage(event){&nbsp; &nbsp; &nbsp; let reader = new FileReader();&nbsp; &nbsp; &nbsp; let file = event.target.files[0];&nbsp; &nbsp; &nbsp; reader.readAsDataURL(file);&nbsp; &nbsp; &nbsp; reader.onload = function(){&nbsp; &nbsp; &nbsp; &nbsp; console.log(reader.result)&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }

MM们

this.files是个类数组吧,取第一个reader.readAsDataURL(file[0]);

繁星淼淼

我想问下我怎么把blob转成base64呀。我获取的字符串为:url("blob:http://localhost:8080/cc116c31-f8f1-47b1-a87b-96d948253495")。请大神赐教
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript