0

I managed to display the binary image from database to image control using generic handler. I want to open the image on new tab or copy it's link address using right click from the mouse. But the URL used is the address of the generic handler (http://localhost:1948/admin/imghndlr.ashx?serial=qwertyuiop). I tried searching but didn't get any results, maybe wrong keywords used. Below is the screenshot of the image in new tab. Right Click>Open image on new tab

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
pemaustria
  • 167
  • 1
  • 2
  • 15

2 Answers2

0

How are you displaying the image?

Your View File should look something like this, of course you need to change data:image/jpeg on what file extension your using.

<img alt="" src="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAsMAAAGhCAIAAAALOi7ZAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QgLEhM6PUSGrwAAIABJREFUeNq8vcuSLEmWHKZ6jnlEZt5761Z3T/eAHAICAYRcEALsuOCWPzbzDfwP/gKXWJACoRDCBSkEBgPhADKY7qnu+4wIdztHuThmHh55q2t6ho+SlpaqyMwID3ez89CjqsY//dM//bM/+zMc/pGE3//PT/z09/1I0t/1Rz/x+o9+0I++vv/n8fU/8MW/9U9+9JVvL/v/u1cy86cv5ttfePXKq//8fTfhp+/qT3/oq8v+6V/+Ay/v25/+4X/46nqO"/>

Also if its a byte file dont forget to Convert it.

Convert.ToBase64String(Foto);
0

You need add data mime-type to make browser know what type does you responsed data is. added code look like below:

public void ProcessRequest(HttpContext context)
{
    //image/png is png mime
    context.Response.ContentType = "image/png";
    //read buffer from database
    context.Response.BinaryWrite(buffer);
}
Johan Shen
  • 158
  • 6