How can I display an image from SQL Server using ASP.NET?

后端 未结 2 1200
逝去的感伤
逝去的感伤 2020-12-19 17:00

Here is my class (product.cs) where is the method to insert the image:

public static void InsertProductIMG(byte[] image, string contentType) 
{
   string cs          


        
相关标签:
2条回答
  • 2020-12-19 17:28

    You need to use a handler to do this

    Read this, a very nice example

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=129

    0 讨论(0)
  • 2020-12-19 17:29

    Create a web page that returns the image. You would select the bytes from the database (as you have already code written to insert, I think you know how to select). Once you have the bytes, you need to set the mime type and write the bytes to the response stream.

    var bytesFromDatabase = getImageFromDatabase();
    context.Response.ContentType = "image/jpeg";
    context.Response.BinaryWrite(bytesFromDatabase);
    

    Edit:

    Just use a img tag with the cource tet to the aforementioned aspx web page. Eg:

    <img src="http://www.example.com/image.aspx?id=1" alt="image" />
    
    0 讨论(0)
提交回复
热议问题