codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Using ASP Classic to Download an Image from SQL Server 2000  bananularstyle at 15:22 on Friday, January 19, 2007
 

Hi everyone,
This is an issue I have been picking away at for the last week now and am out of ideas. Right now I am working on an ASP page that allows a user to submit an ID and select from a list of images that are stored in a SQL Server database. I am able to search for the images, display the results, and get the Internet Explorer download screen. Unfortunately, I am having trouble getting the image to be the file that is downloaded. The link in the results calls a getAttachment.ASP file which triggers the download. Below are the details.

Image Column: ATTACHMENT
Image filename:QM1BM.TIF
Image ID:att_id

-------------------Code---------------------
<% Function GetImageData(ID)

Dim SQL,rs,strConnection
strConnection = "DSN=DPA_Database;uid=my_username;pwd=my_password;DATABASE=My_Database;APP=ASP script;NETWORK=DBMSSOCN;TABLE=my_images"
Set db = Server.CreateObject("ADODB.Connection")
db.Open strConnection

SQL = "SELECT ATTACHMENT FROM dbo.DPA_IMAGES where att_id =" & ID
Set rs = db.Execute( SQL )

GetImageData = rs("ATTACHMENT")

End Function

'If rs.EOF Then Response.End '
Response.ContentType = "application/octet-stream"

' Let the browser know the file name '
Response.AddHeader "Content-Disposition", "attachment;filename=My_image_file_name"


' Let the browser know the file size '
Response.AddHeader "Content-Length", "500000"

'send image To the client from ASP'
Dim ID
ID = 3751
If IsNumeric(ID) Then
Response.BinaryWrite GetImageData(ID)
End If
%>


-----------------------------------

Your help is greatly appreciated.

Thanks,

Leo








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Open new window with content
•  Using ASP Classic to Download an Image from SQL Server 2000
•  Set window position using button
•  Re: how to get LastModified time of a file in repository(in weblogic8.2 )
•  Re: Java Checkers
•  Re: .net
•  trying get the attributes of a file on the internet
•  Date checking script
•  Re: Small Java Program Help


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007