Problem with jQuery color box and dynamic images read via Aspx

To display full-size images on my website I decided to use Jquery.colorbox, this plugin works well with a static image location, for example:

<a rel="ex1" href="http://www.blah.com/image.jpg"><img src="http://www.blah.com/image_thumb.jpg"/></a> 

but when I want to get images from directiry using binary read / write, this plugin shows me garbage data, not compiled jpg / image, as shown below:

 <a rel="ex1" href="http://www.blah.com/getimage.aspx?id=1234"><img src="http://www.blah.com/getimage.aspx?id=1234"/></a> 

and here is my snippet code for getting a 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?

+4
source share
2 answers

Use the colorbox photo property. Example:

$ ('a.example') Colorbox ({photo: true}) ;.

The reason is that colorge regex for automatically detecting image URLs will fail for such a URL (does not contain an image type extension).

+12
source

Some ideas

  • Change the content type to "image/jpeg" (There may be caps)

  • Add the following to the end of the URL &thisisan.jpg (Some browsers will not create an image if they do not see it at the end of the URL)

  • Test by placing the image URL directly into the browser.

+2
source

Source: https://habr.com/ru/post/886062/


All Articles