-1

This is my model image and image saved in database as a binary array. I want to convert image value from array of bytes to string to preview the image.

export class Product{
    constructor(
        public name:string,
        public image:File,
        public quantity:number,
        public price:number,
        public categoryid:number,
        public category:Category,
    ){}
} 

product.component.ts

export class ProductComponent implements OnInit {
    products:Product[]=[]
    constructor(private productServce:ProductService) { }
    ngOnInit(): void {
        this.productServce.GetAll().subscribe(
            res=> 
                {
                    this.products=res
                }
        );
}

product.component.html

<div class="col-sm-12 col-md-6 col-lg-4 col-xl-3" *ngFor="let item of products">
    <div class="box" >
        <img  [src]="item.image" alt="">
        <h3 >{{item.name}}</h3>
        <div class="price"> {{item.price}} </div>
        <div class="stars">
            <i class="fas fa-star"></i>
            <i class="fas fa-star"></i>
            <i class="fas fa-star"></i>
            <i class="fas fa-star"></i>
            <i class="fas fa-star-half-alt"></i>
        </div>
        <a href="#" class="btn">add to cart</a>
    </div>
</div>
Masoud Keshavarz
  • 2,056
  • 7
  • 31
  • 44
  • 1
    Does this answer your question? [How to convert a byte array into an image?](https://stackoverflow.com/questions/4564119/how-to-convert-a-byte-array-into-an-image) – Heretic Monkey May 06 '22 at 20:50
  • You don't want to convert the byte array to a string; you want to convert the byte array to an image, and show that image via an `img` element. That's what the duplicate shows. – Heretic Monkey May 06 '22 at 20:52

0 Answers0