muke77

博客园 首页 新随笔 联系 订阅 管理

查询oracle blob中存储图片并以ashx发布

View Code
  public class getPhoto : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
string photoid= context.Request["photoid"].ToString();

byte[] buffer = getPhotoFromDB(photoid);
context.Response.OutputStream.Write(buffer, 0, buffer.Length);

}

public bool IsReusable
{
get
{
return false;
}
}

private Byte[] getPhotoFromDB(string p_id)
{
string conString = WebConfigurationManager.AppSettings["conString"];
using (OracleConnection conn = new OracleConnection(conString))
{
conn.Open();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT photo_data FROM photo WHERE photo_id = " + p_id;
OracleDataReader reader = cmd.ExecuteReader();
using (reader)
{
reader.Read();
OracleLob blob = reader.GetOracleLob(0);
byte[] buffer = new byte[blob.Length];
blob.Read(buffer, 0, buffer.Length);
return buffer;
}

}


}

 

posted on 2012-02-11 10:05  muke77  阅读(227)  评论(0)    收藏  举报