Home
DBPix
Download
Order
Testimonials
Support
Tutorials
Samples
KnowledgeBase
Links
Revision History
Documentation
Search
Contact
Site Map

Graph: DBPix image storage vs OLE Embedding and Linking in Microsoft Access


DBPix Sample Source Code: getimage.asp
Back to sample
<%  @ LANGUAGE=VBScript %>
<%  Option Explicit %>
<!--#include file="config.inc" -->
<% 
	On Error Resume Next
	' Set expiration headers to promote caching of the image, and set ContentType header to jpeg image
	Response.Expires = 9000000
	Response.Buffer = TRUE
	Response.Clear
	Response.cachecontrol = "public,max_age=30000000"
	Response.ContentType = "image/jpeg"

	Dim cn 
	Dim rs
	Dim SQL
	Dim ItemId
	Dim ImageId

	ImageId = Request("imgid")
	ItemId = Request("itemid")

	If (ImageId <> "" AND ItemId <> "") Then 
		SQL = "SELECT tItems.Image, tItems.Id, tItems.ImageId " &_ 
		      "FROM tItems " &_
		      "WHERE ((tItems.Id=" & ItemId & ") AND (tItems.ImageId=" & ImageId & "))"
		Set cn = Server.CreateObject("ADODB.Connection")
		cn.Open GetConnectString
		Set rs = cn.Execute(SQL)

		' Write image data back to client. Because MIME type is set to image/jpeg the browser will render as picture 
		Response.BinaryWrite rs("Image").GetChunk(rs("Image").ActualSize)

		' Cleanup:
		rs.Close
		Set cn = Nothing
		Set rs = Nothing
	end if
	Response.End
%>

Back to sample