I have a problem with displaying image from my PostgreSQL database in my ASP.NET webforms project. I am uploading an image, save it in the database, and when I want to retrieve it, it does not appear. The code works fine, it does get the string from database, but in console log says there is an error because the string is too long, and the image does not appear. I have tested it with smaller string and the image appears. If anyone could help me I would be very grateful! Here is my code
byte[] LogoFront = System.Text.Encoding.ASCII.GetBytes(dt.Rows[0]["logoFront"].ToString());
string strBase64_logo_front = Convert.ToBase64String(LogoFront);
Session["LogoFront"] = strBase64_logo_front;
logoPreview.ImageUrl = "data:Image/png;base64," + strBase64_logo_front;
HttpPostedFile _LogoFront = btnUploadLogo.PostedFile;
if (_LogoFront.ContentLength > 0)
{
BinaryReader br_frontlogo = new BinaryReader(btnUploadLogo.PostedFile.InputStream);
byte[] bytes_frontlogo = br_frontlogo.ReadBytes((int)btnUploadLogo.PostedFile.InputStream.Length);
base64string_logofront = Convert.ToBase64String(bytes_frontlogo, 0, bytes_frontlogo.Length);
}
else
{
base64string_logofront = Session["LogoFront"].ToString();
}
in my designer file
<asp:Image ID="logoPreview" runat="server"/><br />