Just a couple of thoughts:
The code above posted 16:34 by cmv131 seems to be selecting all records and creating files for all of them .. is this what is intended ? If so I am assuming it is a one off ? Otherwise it would be horridly inefficient to do this every time someone requests their specific blob !
So, if you haven't already, put a where clause in there.
If you go this route you may also want to do a quick check if the file exists before re-building it. Use the FileSystemObject's .FileExists property to check, and if it does, don't bother re-writing to disk. Though it does depend on whether these blob's change regularly or not.
The simplest way for this approach is to write whenever it populates the database, which means the download page can be made quite simple. Sounds like you may not have control over this though.
However, I would personally use an alternative method. This would involve streaming content directly into the response and modifying the http headers to tell the browser that it is a specific type of file (and to download it etc).
example code snippet:
Code:
dim oRS, sSQL, oConn
set oConn = Server.CreateObject("ADODB.Connection")
set oRS = Server.CreateObject("ADODB.Recordset")
oConn.open "your-connection-string"
sSQL = "SELECT FILENAME, FILETYPE, FILEBLOB FROM Attachments WHERE UniqueIDField = 123"
oRS.Open sSQL, oConn, adOpenKeyset, adLockOptimistic [COLOR=green]'You will need to ensure the ADO constants are loaded here. you need either a keyset or static for the get chunk method later to work correctly [/color]
if oRS.EOF and oRS.BOF then
response.write "No Data"
response.end
end if
oRS.movefirst
[COLOR=blue]THE IMPORTANT COUPLE OF LINES[/color]
response.ContentType = "application/x-whatever-your-file-type-is" [COLOR=green]'you can use the filetype in the db, or the file extension to decide this - or just have an x-misc value so that it always downloads, it's not so important[/color]
Response.AddHeader "content-disposition","attachment; filename=" & oRS.Fields("FILENAME") & ";"
dim lSize, lChunk, lPos
lSize = oRS.Fields("FILEBLOB").ActualSize
lChunk = 1000 [COLOR=green]'Whatever chunk size you want, change this to optimise etc[/color]
lPos = 0
while lPos < lSize
response.write(oRS.Fields("FILEBLOB").GetChunk(lChunk))
lPos = lPos + lChunk
wend
oRS.close : set oRS = nothing
oConn.close : set oConn = nothing
The reason I've used the GetChunk method here rather than just dumping the entire file is for load / processing efficiency - though if most of the files are a few KB in size then don't bother - just dump the entire field as normal, but when you have MB's to deal with it can start to overload the server under high usage.
You'll probably notice that there is no HTML, at all - this is the idea, you're sending the blob as the content and telling the browser via the http header that it is a downloadable file, and not html. Therefore I would suggest that you open this page as a new window / pop up, using normal GET or POST variables to tell the page which blob to get. In most browsers this results in a download dialog box only (no new window) leaving the initial window intact.
I've written the above code on the fly, so you'll need to adapt it to your requirements, test it thoroughly, and watch out for typo's..
Hope that helps.
A smile is worth a thousand kind words. So smile, it's easy! 