查询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;
}
}
}

浙公网安备 33010602011771号