fibreiv wrote:
I am trying to download files from my database that I uploaded to it.
I can download bmp, txt file but have not been able to d/l pdf files. I am
able to d/l pdf files stored in the file system but not in the database. Any
help would be great. Here is my code, I have hard coded the file to
download for testing purposes.
Connect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Password=;Initial Catalog=INNB;Data Source=pompom"
Set db = Server.CreateObject("ADODB.Connection")
db.Open Connect
SQL = "SELECT filesize, contenttype, filename, filedata FROM
thefiles where id = 2"
Set rs = db.Execute( SQL )
If rs.EOF Then Response.End
Response.ContentType = "application/pdf"
Response.AddHeader "Content-Disposition",
"attachment;filename=agencies.pdf" Response.AddHeader "Content-Length", "16863"
Response.BinaryWrite rs("filedata")
So what kind of error do you get? How do you know the length is
16863??
When I do my binary retrieves I don't specify the length.
Here's my generic getbinary.asp page... When a file is uploaded I store
the mime type of the file.
<!-- #INCLUDE VIRTUAL="/adovbs.inc" -->
<%
ID = Request.QueryString("ID")
tablename=Request.QueryString("tablename")
idfieldname=Request.QueryString("idfieldname")
datafield=Request.QueryString("datafield")
datacon=session("DB_CONNECTIONSTRING")
Set con2 = Server.CreateObject("ADODB.Connection")
Con2.open(datacon)
mysql2="select * from " & tablename &" where "& idfieldname & "=" & ID
Set rs2=con2.execute(mysql2)
if not rs2.EOF then
Response.ContentType = rs2("type_"&right(datafield,
len(datafield)-4))
Response.BinaryWrite(rs2(datafield))
else
Response.Write("Record '" + ID + "' not found.")
end if
rs2.Close
%>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Microsoft Theme" content="none, default">
</head>