for showing full size images on my site I’ve decided to use Jquery.colorbox , this pluging works well with static image location like :
<a rel="ex1" href="http://www.blah.com/image.jpg" rel="nofollow noreferrer noopener"><img src="https://www.blah.com/image_thumb.jpg"/></a>
but when I want to get the images from a directiry using binary read/write this plugin showing me garbage data not a compiled jpg/image like following :
<a rel="ex1" href="http://www.blah.com/getimage.aspx?id=1234" rel="nofollow noreferrer noopener"><img src="https://www.blah.com/getimage.aspx?id=1234"/></a>
and here is my snippet code for getting dynamic image :
thumbLocation = DataHelper.GetItemPicture(recordID);
using (FileStream IMG = new FileStream(thumbLocation, FileMode.Open))
{
//FileStream IMG = new FileStream(thumbLocation, FileMode.Open);
byte[] buffer = new byte[IMG.Length];
IMG.Read(buffer, 0, (int)IMG.Length);
Response.Clear();
Response.ContentType = "image/JPEG";
Response.AddHeader("Content-Length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
Response.End();}
how can I fix the problem?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Use colorbox’s photo property. Example:
$(‘a.example’).colorbox({photo:true});
The reason is that colorbox’s regex to auto-detect image URLs is going to fail for that kind of URL (doesn’t contain an image-type extension).
Method 2
Some ideas
-
Change the content type to
"image/jpeg"(The caps might matter) -
Add the following to the end of the url
&thisisan.jpg(Some browsers will not create an image if they don’t see this at the end of the url) - Test by putting the image url directly into the browser.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0