Sql-从数据库读取图像
在从数据库读取图像时,我不断得到错误图像图标 以下是HttpHandler代码:Sql-从数据库读取图像,sql,image,httphandler,Sql,Image,Httphandler,在从数据库读取图像时,我不断得到错误图像图标 以下是HttpHandler代码: public void ProcessRequest(HttpContext context) { .... //After we got the data table: byte[] image = (byte[])dt.Rows[0]["Picture"]; context.Response.ContentType = dt.Rows[0]["PictureType"].ToSt
public void ProcessRequest(HttpContext context) {
....
//After we got the data table:
byte[] image = (byte[])dt.Rows[0]["Picture"];
context.Response.ContentType = dt.Rows[0]["PictureType"].ToString();
context.Response.BinaryWrite(image);
}
我确实检查并看到image
不是空的(应该是一个非常大的数组),并且PictureType
确实保存了以前保存在db中的图片类型。但调用处理程序时仍会看到错误图像图标:
<img src='myhandler.ashx?imgid=someid'/>
发生这种情况的原因是什么?PictureType列中有什么?在数据库中存储图像=错误。是否可以将它们存储在公用文件夹中,而只将URL存储在数据库中?@MitchWheat,上载图像时,我保留asp.net文件上载控件中的
ContentType
属性。这保存在PictureType
@arxanas中,我想这也是一种选择。但我的网站现在的工作方式,只会让事情变得比应该的更复杂。我宁愿解决这个问题。您的表是否设置了正确的编码?