Javascript 角度:I';我无法显示使用Base64字符串创建的文件中的图像

Javascript 角度:I';我无法显示使用Base64字符串创建的文件中的图像,javascript,angular,file,base64,blob,Javascript,Angular,File,Base64,Blob,所以我创建了一个调整图像大小的指令。基本上它是有效的-我得到的Base64字符串是大小调整后的图像(我正在使用这个页面进行测试:) 让我们转到代码: changeEvent(imageResult: ImageResult) { const dataURL = imageResult.resized && imageResult.resized.dataURL ? imageResult.resized.dataURL : (imageResult.dataURL ?

所以我创建了一个调整图像大小的指令。基本上它是有效的-我得到的Base64字符串是大小调整后的图像(我正在使用这个页面进行测试:)

让我们转到代码:

  changeEvent(imageResult: ImageResult) {
    const dataURL = imageResult.resized && imageResult.resized.dataURL ? imageResult.resized.dataURL : (imageResult.dataURL ? imageResult.dataURL : null);
    if (!dataURL) {
      return;
    }

    const blob = this.dataURItoBlob(dataURL, imageResult.file.type);
    const file = new File([blob], imageResult.file.name, {type: imageResult.resized ? imageResult.resized.type : 'image/jpeg'});
    this.fileEvent.emit(file);
  }

  dataURItoBlob(dataURI, type: string) {
    const arrayBuffer = new ArrayBuffer(dataURI.length);
    const int8Array = new Uint8Array(arrayBuffer);
    for (let i = 0; i < dataURI.length; i++) {
      int8Array[i] = dataURI.charCodeAt(i);
    }

    return new Blob([int8Array], { type });
  }
有人能告诉我我做错了什么吗

  private createImageUrl(file: File) {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onloadend = () => {
      this.fileName = file.name;
      if (this.hasThumbnail(file.name)) {
        this.imageUrl = reader.result;         <==== base64 is different
        this.thumbnail = reader.result;
      }
    };
  }