开发者

How to retrieve image from database?

开发者 https://www.devze.com 2023-03-11 04:59 出处:网络
I want to save and开发者_StackOverflow社区 retrieve the image from local database. I insert image as blob in db but I am usable to retrieve image.

I want to save and开发者_StackOverflow社区 retrieve the image from local database. I insert image as blob in db but I am usable to retrieve image.

Please help me.

Thanks Monali


What error are you getting? Using LINQ to SQL, the following code creates an HttpHandler and grabs a BLOB from a database...

public class GetFile : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        Document document = new GigzDataContext().Documents.SingleOrDefault(p => p.Id == new Guid(context.Request.QueryString["Id"].ToString()));
        context.Response.ContentType = document.ContentType;
        context.Response.BinaryWrite(document.Blob.ToArray());
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}


See this link to have a concept on how to retrieve blob data from a database table as bytes, and after you have them in bytes, you should be able to save them into proper format to form your final image.

0

精彩评论

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