开发者

colorbox problem when reading image from database

开发者 https://www.devze.com 2023-02-25 19:50 出处:网络
I\'m developing a project using asp.net mvc. And i am saving images to database as byte array. Every thing works properly until when iam using colorbox.

I'm developing a project using asp.net mvc. And i am saving images to database as byte array. Every thing works properly until when iam using colorbox.

I try to using colorbox to show set of product images. when i am click to button i am getting weird result. I am expecting image but its gathering huge amount of weird symbols like below.

<�<�="=a=�=�> >`>�>�?!?a?�?�@#@d@�@�A)AjA�A�B0BrB�B�C:C}C�DDGD�D�EEUE�E�F"FgF�F�G5G{G�HHKH�H�IIcI�I�J7J}J�KKSK�K�L*LrL�MMJM�M�N%NnN�OOIO�O�P'PqP�QQPQ�Q�R1R|R�SS_S�S�TBT�T�U(UuU�VV\V�V�WDW�W�X/X}X�YYiY�ZZVZ�Z�[E[�[�\5\�

Iam sure that works properly including colorbox. Problem occurs when colorbox tries ta get image from database. Any ideas?

Thanks in advanc开发者_运维技巧e

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 the pattern of url. for getting image.

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

this is how i call color box.

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

this is the how i embed the element to page.


Solution available at Problem while working with Jquery colorbox and dynamic images that reading via Aspx

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).


The weird symbols you've posted are because the bytes are being interpreted as text, and they won't all be valid/printable characters. This is not necessarily a problem.

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

What datatype is the field in the database? Make sure you're not using a text field, as this would certainly screw things up. It might be worthwhile copy/pasting the bytes you're saving to the database and the ones you're getting back out and checking whether they're the same. If they're not, then chances are something is wrong in the database (like the field type).

0

精彩评论

暂无评论...
验证码 换一张
取 消