Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download BLOB

Status
Not open for further replies.

sorcha999

Programmer
Jul 23, 2002
14
US
We have an application that allows users to insert documents via linking or embedding. I am attempting to create a webpage that will allow other users to download/view these documents. I am able to get this working for the linked documents but not for all embedded documents. I am only able to view the following types:
Microsoft Word (.doc)
Microsoft Excel (.xls)
Microsoft PowerPoint (.ppt)
Adobe Acrobat (.pdf)
Text (.txt)
Rich Text (.rtf)
JPEG Images (.jpg)
GIF Images (.gif)
TIF Imaged (.tif)
Hypertext Documents (.htm)

I need to be able to download any type of document they choose to embed. Below is my code:

'Connection.asp
<%
Dim conn
set conn=Server.CreateObject("ADODB.Connection")
conn.open "DSN=DEMO6","SA","SA"
%>
'embedfile.asp
<!--#INCLUDE FILE="../Connection/CONNECTION.ASP"-->
<%
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear

Response.ContentType = "application/octet-stream"

Set rs = conn.Execute("SELECT EMBED_OBJECT FROM LINK_EMBED WHERE LINK_EMBED_SYSID='0000025'")
Response.BinaryWrite rs("EMBED_OBJECT")
Response.End
%>
 
When you store the blob, store the content type as well. Then use:


Set rs = conn.Execute("SELECT EMBED_OBJECT,ContentType FROM LINK_EMBED WHERE LINK_EMBED_SYSID='0000025'")

Response.ContentType = rs("ContentType")
Response.BinaryWrite rs("EMBED_OBJECT")
 
Thank you for the response.

I do not want to make any changes to the database for this. Even if I change the content type to:

Response.ContentType = "application/zip"

and then try to download an embedded zip file it will not work.
 
I figured it out. The result is:

<%@ LANGUAGE="VBSCRIPT" %>
<!--#INCLUDE FILE="../Connection/CONNECTION.ASP"-->
<%
Dim rs,EmbedCode
Set EmbedCode=Request.QueryString("embedcode")

Set rsfile = CONN.Execute("SELECT FILE_LOCATION FROM LINK_EMBED WHERE LINK_EMBED_SYSID='" & EmbedCode & "'")


Dim FileExtension
Dim tempArr
IF TRIM(rsfile("FILE_LOCATION"))<>"" OR NOT ISNULL(rsfile("FILE_LOCATION")) THEN
tempArr = Split(rsfile("FILE_LOCATION"), ".")
FileExtension=UCase(tempArr(UBound(tempArr)))
END IF

SELECT CASE FileExtension
CASE "DOC"
Response.ContentType = "application/msword"
CASE "GIF"
Response.ContentType = "image/gif"
CASE "JPG"
Response.ContentType = "image/jpeg"
CASE "XLS"
Response.ContentType = "application/x-msexcel"
CASE "PDF"
Response.ContentType = "application/pdf"
CASE "TXT"
Response.ContentType = "text/plain"
CASE "HTM"
Response.ContentType = "text/html"
CASE "TIF"
Response.ContentType = "image/tiff"
CASE "RTF"
Response.ContentType = "application/rtf"
CASE "PPT"
Response.ContentType = "application/vnd.ms-powerpoint"
CASE "ZIP"
Response.ContentType = "application/zip"
CASE ELSE
Response.ContentType = "application/octet-stream"
END SELECT
Response.AddHeader "Content-Disposition", "filename=" & rsfile("FILE_LOCATION")

Set rs = CONN.Execute("SELECT EMBED_OBJECT FROM LINK_EMBED WHERE LINK_EMBED_SYSID='" & EmbedCode & "'")
Response.BinaryWrite rs("EMBED_OBJECT")
Response.End
%>
 

if I wanted to extract(copy) blobs (mostly pdfs) from a sql server table to (into) a folder on the network.

would the solution above help me.

thanks.

LikeThisName <- ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top