Jeú Casulo
Jeú Casulo

Reputation: 147

Chrome and Firefox do not display image from database

Im having a problem to retrieve image from the database with Entity FrameWork 6 on Chrome and Firefox, I do not have that problem with Internet Explorer. It is the third "method" I have tried and both reach the same result. It's is a simple web app that saves and retrieves image from database, the text and number columns is working fine, only image does not work.

SaveMethod

protected void btnSave_Click(object sender, EventArgs e)
{
// Code for Save Image
if (FUImage.HasFile)
{
    int length = FUImage.PostedFile.ContentLength;
    byte[] img = new byte[length];
    FUImage.PostedFile.InputStream.Read(img, 0, length);
    ImageGallery ig = new ImageGallery
    {
        SLID = 0,
        ImageTitle = txtImageTitle.Text.Trim(),
        Picture = img
    };
    using (MyDatabaseEntities1 dc = new MyDatabaseEntities1())
    {
        dc.ImageGalleries.Add(ig);
        dc.SaveChanges();
        lblMsg.Text = "Successfully Saved";

        // populate Gallery image Here
        PopulateGallery();
    }
}
}

Select method

private void PopulateGallery()
{
// here code for populate image gallery
using (MyDatabaseEntities1 dc = new MyDatabaseEntities1())
{
    List<ImageGallery> imgGallery = new List<ImageGallery>();
    imgGallery = dc.ImageGalleries.ToList();
    gvGallery.DataSource = imgGallery;
    gvGallery.DataBind();
}
}

Convert method

protected string GetImageString64(byte[] Image)
{
// For convert byte image to base 64 string
string base64String = Convert.ToBase64String(Image, 0, Image.Length);
return "data:image/png;base64 ," + base64String;
}

Template with Eval in GridView

                    <asp:TemplateField ItemStyle-Width="150px">
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" Width="100px" ImageUrl='<%#Eval("Picture").ToString() == ""?"": GetImageString64((byte[])Eval("Picture")) %>' />
                    </ItemTemplate>
                    </asp:TemplateField>

The question is that the webapp is working perfeclty in IE but not in Chrome and Firefox and I cant find the anwaser anywhere, by the way, Im begginer with aspnet, and I ONLY need a site that saves and retrieves images, does not need to be with entity, so ANY solution or sugestion will be gratefull.

Thank for all of you.

Upvotes: 0

Views: 163

Answers (1)

Pragnesh
Pragnesh

Reputation: 26

Save only filename in database table and save image in your server path and called image from the server on your aspx page...

Upvotes: 1

Related Questions