Home:ALL Converter>Angular base64 image pipe, Maximum call stack size exceeded

Angular base64 image pipe, Maximum call stack size exceeded

Ask Time:2017-11-22T02:41:00         Author:daniel

Json Formatter

I have to convert Image urls to base64 encoded strings (because of this)

import { Pipe, PipeTransform } from '@angular/core';


declare var base64;

@Pipe({
  name: 'tobase64'
})
export class Tobase64Pipe implements PipeTransform {

  transform(value: any, args?: any): any {
    var xmlHTTP = new XMLHttpRequest();
    xmlHTTP.open('GET', value, true);
    xmlHTTP.responseType = 'arraybuffer';
    xmlHTTP.onload = (e) => {
        console.log('e',e);
      var arr = new Uint8Array(e.currentTarget.response);
      var raw = String.fromCharCode.apply(null, arr);
      var b64 = base64.encode(raw);
       var dataURL = "data:image/png;base64," + b64;
      return dataURL;
    };
    xmlHTTP.send();

    return null;
  }

}

Html

<image x="0" y="0" width="500" height="500" [attr.xlink:href]="'assets/hand.jpg' | tobase64"    mask="url(#hole)" />  

Error:

ERROR RangeError: Maximum call stack size exceeded

Author:daniel,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/47420396/angular-base64-image-pipe-maximum-call-stack-size-exceeded
yy