[thelist] Retrieving OLE File from Access DB with Classic ASP

Chris evolt at cubeit.co.uk
Mon Dec 19 01:57:09 CST 2005


Ken,

The code I'm using to extract the image from the database is below.  Problem
with getting the PDF data back out the database is I can't find any examples
using Classic ASP.  Google has examples in PHP and ASP.NET, neither of which
I understand.  

I'd like to be able to provide options to open the PDF in a browser window
and to stream it to the client's browser as a 'save to' option.

Any ideas?

Thanks.

<%
Dim oConn
Dim oRs
Dim sSQL
Dim nFileID

nFileID = Request.QueryString("propertyID")

If Not nFileID = "" And IsNumeric(nFileID) Then

	Set oConn = Server.CreateObject("ADODB.Connection")
	Set oRs = Server.CreateObject("ADODB.Recordset")

	oConn.Open strDSN

	sSQL = "SELECT fldImageFileType, fldImage FROM tblProperties WHERE
propertyID = " & Request.QueryString("propertyID") & ";"

	oRs.Open sSQL, oConn, 3, 3

	If Not oRs.EOF Then
		Response.ContentType = oRs("fldImageFileType")
		Response.BinaryWrite oRs("fldImage")
	Else
		Response.Write("File could not be found in database.")
	End If

	oRs.Close
	oConn.Close

	Set oRs = Nothing
	Set oConn = Nothing
Else
	Response.Write("There was an error.")
End If
%>

> -----Original Message-----
> From: thelist-bounces at lists.evolt.org [mailto:thelist-
> bounces at lists.evolt.org] On Behalf Of Ken Schaefer
> Sent: 19 December 2005 00:15
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] Retrieving OLE File from Access DB with Classic ASP
> 
> > -----Original Message-----
> > From: thelist-bounces at lists.evolt.org [mailto:thelist-
> > bounces at lists.evolt.org] On Behalf Of Chris Dempsey
> > Subject: Re: [thelist] Retrieving OLE File from Access DB with Classic
> ASP
> >
> > Nobody able to help?  I re-wrote the script to use the filesystem as we
> > had to meet deadline but I'd still be interested if someone can advise
> > how to retrieve a PDF or other file [other than an image] from a
> > Database.
> 
> I've seen this done with SQL Server, which is a database. I've never seen
> anyone do it with Access. That said, it's just binary data, so you should
> be
> able to get it out somehow.
> 
> What's the code you're using at the moment? And what are the problems
> you're
> running into?
> 
> Cheers
> Ken
> 
> 
> >
> > > -----Original Message-----
> > > From: thelist-bounces at lists.evolt.org [mailto:thelist-
> > > bounces at lists.evolt.org] On Behalf Of Chris
> > > Sent: 15 December 2005 10:20
> > > To: thelist at lists.evolt.org
> > > Subject: Re: [thelist] Retrieving OLE File from Access DB with Classic
> > ASP
> > >
> > > > Why are you storing the file in the database?
> > > I knew someone would ask and I have my excuse ready.  I chose to store
> > > both
> > > the PDF and image in the database for ease of backup - simply download
> > the
> > > database.
> > >
> > > Security is not the issue as the files are all freely available to
> > > download
> > > from the site.  The site will hold a maximum of 70x 250kb PDFs at any
> > one
> > > time and will be low traffic - maybe 100 visitors per day max.
> > >
> > > Technically I know it's not the best solution but I think it should be
> > > fine
> > > for this site.
> > >
> > > Can anyone advise how I would stream the file back out of the
> database?
> > >
> > > Thanks.
> > >
> > >
> > > > Chris Dempsey wrote:
> > > >
> > > > > I have written code to take a PDF file and insert it into an
> Access
> > > > > Database field via a form and file upload script.  Unfortunately
> I'm
> > > > > struggling to get it back out.
> > > >
> > > > Why are you storing the file in the database? Your Access file is
> > going
> > > > to end up the size of a cow.
> > > >
> > > > Why not upload the file to a folder, and store only the filename in
> > the
> > > > DB?
> > > >
> > > > If the concern is unauthorised downloading of the file, it should be
> > > > possible to upload the file to a folder outside of the web root, and
> > > > provide an ASP-based means to download it for an authenticated user.
> > > >
> > > > I haven't done this, but believe it to be possible - can anyone
> > confirm?
> > > > I'm going to be building something similar soon.
> > > >
> > > > Cheers
> > > >
> > > > Ian
> --
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !




More information about the thelist mailing list