Problem with colorbox while reading image from database

I am developing a project using asp.net mvc. And I save the images to the database as an array of bytes. Everything works fine until iam uses colorbox.

I am trying to use colorbox to display a set of product images. when I press the button, I get a strange result. I expect the image, but its collecting a huge amount of strange characters, as shown below.

<<= "= a = = →` →?!? a ?? @ # @d @ @ A) AjA A B0BrB B C: C} CDDGDDEEUEEF "FgFFG5G {GHHKHHIIcIIJ7J} JKKSKKL * LrLMMJMMN% NnNOOIOOP'PQRQQQQQQQQQQQQQQQQQQQQQQ | RSS_SSTBTTU (UuUVV \ VVWDWWX / X} XYYiYZZVZ Z [ [[\ 5 \

I am sure that it works correctly, including colorbox. The problem occurs when colorbox tries to get an image from the database. Any ideas?

Thanks in advance

public FileContentResult Index(int id) { var media = _entities.Images.AsQueryable() .Where(e => e.Id == id) .Select(e => e).FirstOrDefault(); return File(media.ImageData, media.ImageMimeType); } 

this is hove, i get the image.

 http://localhost:2632/assets/index/105 

this is url template. to get an image.

 $("a[rel=" + "'" + 48 + "']").colorbox({ transition: "fade", title: true, current: true }); 

this is how i call the color box.

 <a style=" display:none;" rel="48" href="assets/index/107">asd</a> 

this is how i insert the element into the page.

+6
source share
2 answers

The solution is available in Problem when working with jQuery color boxes and dynamic images that are read through Aspx

Use the colorbox photo property. Example:

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

The reason is because colorge regex to automatically detect image URLs crashing for such URLs (do not contain image type extension).

+13
source

The weird characters you posted are that the bytes are interpreted as text, and they will not all be valid / printable characters. This is not necessarily a problem.

What happens when you submit a request ( http://localhost:2632/assets/index/105 )? What does the browser show?

What type of data is the field in the database? Make sure that you do not use the text box, as this will certainly hurt. It might be worth copying / pasting the bytes that you save into the database, and those that you get back, and check if they are the same. If this is not the case, then the likelihood that something is wrong in the database (for example, the type of field).

0
source

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


All Articles