Home > Software design >  Send image from ASP.NET Web API to Angular client
Send image from ASP.NET Web API to Angular client

Time:03-25

I just finished my photos upload functionality. I'm storing images in folder after upload and I'm storing path to them in my database.

I want to display this photos in my Angular client and I don't know how can I do this. I can't just send a path to images because I want to display this photos in different components. Is there any solution that gives me possibility to send images from .NET backend to Angular client, and how to display this images on my web?

CodePudding user response:

If you have a path to your image, you can just simply get this path from your database and encode your image to Base64 like this:

byte[] bytes = File.ReadAllBytes(dbObject.Path);
string image = Convert.ToBase64String(bytes);

and send this string to your Angular client.

If you already get response in your client, you can just simply display image from Base64 with something like this:

<img [src]="'data:image/png;base64,' response.image">
  • Related