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.
Asked
Active
Viewed 835 times
0

Uwe Keim
- 39,551
- 56
- 175
- 291

pemaustria
- 167
- 1
- 2
- 15
-
Have you converted back the binary data to image before setting to the control? – M. Adeel Khalid Feb 07 '17 at 04:16
-
3that looks like a PNG (see first few letters) but sent with the wrong content/mime type headers see here http://stackoverflow.com/a/1031144/74585 – Matthew Lock Feb 07 '17 at 04:18
2 Answers
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);

Franz Justin Buenaventura
- 366
- 3
- 20
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