Convert Blob to image url and use in image src to display image

Discussão em 'Angular' iniciado por pjay, Março 18, 2025.

  1. pjay

    pjay Guest

    How to convert blob to base64/image?
    I am getting this blob through API call and I am trying to display it in a
    image. I have tried with stackoverflow answers but nothing could help so
    I just tried this.

    //Angular 5 code
    imageSrc;//global variable
    data = [{"image_blob":{"type":"img/jpg","data":[123,125]}}];//from api
    var blob1 = new Blob([new Uint8Array(data[0].image_blob.data)]);
    const imageUrl = URL.createObjectURL(blob1);
    console.log(imageUrl);//blob:http://localhost:8100/c489.etc
    this.imageSrc = imageUrl;

    <!-- html code -->
    <img [src]='imageSrc' alt="image">


    Have missed anything. Please suggest

    Continue reading...

Compartilhe esta Página