Downloading files of known mime type

B

Bret Thompson

I am attempting to write an ASP page that will download a file rather then
open it, when it is of known type. I found this code here:
http://mosley.arach.net.au/dev/docs/save as.htm

The first example works fine, for files under 5 Mb, the second example
downloads the file but the data is corrupted. Using a JGP file as a
reference, it seems to corrupt the end of the file (since the bottom of the
JPEG is corrupted).

Here is the code I am using. Any idea how to fix this? or an alternative
method?


Response.ContentType = "application/x-unknown"
Response.AddHeader "content-disposition","attachment; filename=" &
Request.QueryString("File")

Set adoStream = CreateObject("ADODB.Stream")
chunk = 2048
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(Server.MapPath(vFilePath))

iSz = adoStream.Size

Response.AddHeader "Content-Length", iSz

For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then Exit For
Response.BinaryWrite adoStream.Read(chunk)
Next

If iSz Mod chunk > 0 Then
If Response.IsClientConnected Then
Response.BinaryWrite objStream.Read(iSz Mod chunk)
End If
End If

adoStream.Close
Set adoStream = Nothing

Response.End
 
B

Bret Thompson

Ray,

Your link is the exact same code at the correct site. Scroll down to the
part that says
"Many people have complained that larger files simply do not work."
And you will see where I got the code with the "Chunks". This is thier
solution for large files.

The first code example fails with files larger then roughly 5 Mb.

Bret
 
B

Bret Thompson

Ray,

Nevermind, I finally found it. There is a typo in thier code. Look at the
2 Response.BinaryWrite statements:
Response.BinaryWrite adoStream.Read(chunk)
Response.BinaryWrite objStream.Read(iSz Mod chunk)

Bret
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top