|
-
Jan 26th, 2005, 07:03 AM
#1
Thread Starter
New Member
Retriving images from a database
Hey all I need some help with displaying some images that are in a database. Currently when I try to display them they come out in binary form and I am stumped on how to correct it.
Server info:
WWW Server:
Windows Server 2003
ASP .Net
Pages are .aspx written in VBScript
Database Info:
MS SQL Server 2000
Problem code:
<%
Dim rs
rs = Server.CreateObject("adodb.recordset")
rs.Open("Select * From avatar", Application("Conn"))
If not rs.eof then
Do Until rs.eof
Response.ContentType = "image/gif"
Response.binarywrite(rs.fields("a_avatar").value)
rs.movenext
Loop
rs.close
End If
%>
As stated above the result is display of the three images in the database in binary form.
http://test.adiktclan.com/test.aspx
Any help is greatly appreciated.
Thanks,
John K
MCSA, A+
-
Jan 26th, 2005, 11:12 AM
#2
Frenzied Member
Re: Retriving images from a database
This is code from my dbimage.aspx page.
PHP Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace PKPromo.Web.Images
{
/// <summary>
/// Summary description for Image.
/// </summary>
public class Image : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if(Request["pid"] != "" && Request["pid"] != null)
{
Business.Images.Image img = new Business.Images.Image(new System.Guid(Request["pid"]));
Response.ContentType = "Image/jpeg";
Response.BinaryWrite(img.Raw);
Response.Flush();
Response.End();
}
else
{
Response.ContentType = "Image/jpeg";
Response.Flush();
Response.End();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
C# but you should be able to get the idea. Basicly you just turn the page into an image. <img src="dbimage.aspx?pid=imageid">
The important parts are the content type and the binary write.
Magiaus
If I helped give me some points.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|