|
-
Jan 26th, 2005, 06:52 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, 07:31 AM
#2
Re: Retriving images from a database
I was going to say read Beacons tutorial.. but since you are using Asp, don't you have to store the pic in a temp folder and delete it after say twenty mins?
You'd still have to point to a file for the users browser to determine that it's an image.
I may be wrong tho
Have you tried searching online via google or something for this?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jan 26th, 2005, 07:42 AM
#3
Thread Starter
New Member
Re: Retriving images from a database
Yes, but i get the information on how to do in ASP which i can get working but don't know what i am missing to get working in ASP .Net. As you can see from the link on the orignal post i get the binary from the database but doesn't get on converted back to "image". If i put inside a <img> tag all i get is small image boxes with nothing in them.
-
Jan 26th, 2005, 08:09 AM
#4
Re: Retriving images from a database
Check out this link:
http://www.codeproject.com/aspnet/in...isse_part6.asp
(Here is the search I did, and that link was the first one listed, but there may be others that could help as well, so here is my Goggle search: http://www.google.com/search?hl=en&q...=Google+Search )
-
Jan 26th, 2005, 08:21 AM
#5
Re: Retriving images from a database
 Originally Posted by mcp87
Yes, but i get the information on how to do in ASP which i can get working but don't know what i am missing to get working in ASP .Net. As you can see from the link on the orignal post i get the binary from the database but doesn't get on converted back to "image". If i put inside a <img> tag all i get is small image boxes with nothing in them.
Yes you will have to use Img tag. This is how I do it.
First Put the code in a separate asp file, lets say GetImage.asp
Now modify it so it can accept a parameter so we can show fetch one image at a time. e.g
VB Code:
<%
Dim rs
dim ID
ID = Request.QueryString("ID")
rs = Server.CreateObject("adodb.recordset")
rs.Open("Select * From avatar Where AvatarID=" & ID, Application("Conn"))
if not rs.eof then
Response.ContentType = "image/gif"
Response.binarywrite(rs.fields("a_avatar").value)
end if
rs.close
%>
Now in a spearate page where you want to display the Image
Just loop through the record and pass the ID.
e.g
Do while not rs.eof
response.write "<img src='GetImage.asp?ID=" & rs("ID") & "'>"
rs.movenext
loop
That should work.
BTW: I have posted some example and links for this sort of thing on this and database forum. Search my post you will find them, not that most of the solution I posted are for ASP and not asp.net.
Ecniv, you can generate dynamic image like this without the need of pointing to any file.
Last edited by Danial; Jan 26th, 2005 at 08:33 AM.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Jan 27th, 2005, 03:14 AM
#6
Thread Starter
New Member
Re: Retriving images from a database
Ok i have it setup now like you suggested, the binary on the screen is gone but all i have now is image boxes with red x's. here ill post both of my files maybe i am over looking something simple and dumb.
test.aspx
VB Code:
<%@ Page aspCompat="True" %>
HTML Code:
<html>
<body>
<center>
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="/test.aspx?content=processing">
File 1:<INPUT TYPE=FILE NAME="FILE1" size="20">
<INPUT TYPE=SUBMIT VALUE="Upload!">
</FORM
</center>
VB Code:
<%
Dim rs
Dim Upload
Dim File
If Request.QueryString("content") = "processing" Then
Upload = Server.CreateObject("Persits.Upload.1") '
Upload.Save
rs = Server.CreateObject("adodb.recordset")
rs.CursorType = 1
Rs.LockType = 2
rs.Open("avatar", Application("Conn"))
rs.AddNew
File = Upload.Files("FILE1")
If Not File Is Nothing Then
rs("a_avatar").Value = File.Binary
rs.Update
End If
Response.Write("File added to database")
Rs.close
End If
rs = Server.CreateObject("adodb.recordset")
rs.Open("avatar", Application("Conn"))
Do Until Rs.Eof
Response.Write("<img src='test2.aspx?id=" & rs.fields("a_id").value & "'>")
Rs.MoveNext
Loop
Rs.Close
%>
HTML Code:
</body>
</html>
test2.aspx
VB Code:
<%@ Page aspCompat="True" %>
<%
dim rs
rs = Server.CreateObject("adodb.recordset")
rs.Open("Select * From avatar where a_id ='" & Request.QueryString("id") & "'", Application("Conn"))
Response.ContentType = "image/jpeg"
Response.binarywrite(rs("a_avatar").value)
rs.movenext
rs.close
End If
%>
Last edited by mcp87; Jan 27th, 2005 at 03:18 AM.
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
|