You can read the image from the database as a binary block. This will be read as a byte [] array. Then this byte [] can be sent to the browser using Response.BinaryWrite and the image content type / (type) - jpg / png / gif.
The call will look something like this:
<img src="showmyimages.aspx?image=id" />
And the code will look something like this:
result = myWebService.GetImage (id);
if (result != null) && result.Length > 0
{
Context.Response.ClearContent();
Context.Response.ClearHeaders();
Context.Response.ContentType = "image/gif";
Context.Response.AddHeader("Content-Length", result.Length.ToString(System.Globalization.CultureInfo.CurrentCulture));
Context.Response.AddHeader("content-disposition", String.Format("inline; filename={0}.gif", filename));
Context.Response.BinaryWrite(result);
Context.Response.End();
}
This masks the file name a bit, but allows binary direct reading from the database without a permanent image on disk.
EDIT:
, , , , . - , , , StreamReader, , WebResponse.GetResponseStream()
EDIT:
, , ( ), , , , . , select, fldImage.FileData.
public void ProcessRequest(HttpContext context)
{
string qry = "SELECT [Image], ID, [Images.Image.FileData] AS FileData, ";
qry += "[Images.Image.FileName] AS FileName, [Images.Image.FileType] AS FileType";
qry += " FROM Images WHERE (ID = 1)";
string connect = @"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=##PathToDB##\Database1.accdb";
using (OleDbConnection conn = new OleDbConnection(connect))
{
if (context.Request.QueryString["id"] != null)
{
OleDbCommand cmd = new OleDbCommand(qry, conn);
cmd.Parameters.AddWithValue("ID", context.Request.QueryString["id"]);
conn.Open();
using (OleDbDataReader rdr = cmd.ExecuteReader())
{
if (rdr.HasRows)
{
rdr.Read();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "image/" + rdr["FileType"];
byte[] result = Encoding.UTF8.GetBytes(rdr["FileData"].ToString());
context.Response.AddHeader("Content-Length",
result.Length.ToString(System.Globalization.CultureInfo.CurrentCulture));
context.Response.AddHeader("content-disposition",
String.Format("attachment; filename={0}", rdr["FileName"]));
context.Response.BinaryWrite(result);
context.Response.End();
}
}
}
}
}
, Microsoft Office Interop, MSDN, . , , . Microsoft.Office.Interop.Access.Dao. COM Microsoft Office 12.0 Access Database Engine Objects Library. " ".