http download corrupting zip file

D

Derrick

I have an http download that streams a zip file to client, after download I
am getting "Error [file name] start of central directory not found; Zip file
corrupt. Possible casue: file transfer error."

Ring any bells? Here's the asp code, thanks in advance!!

Derrick

...
Response.ContentType = "application/zip"
Response.AddHeader "Content-Disposition", "attachment; filename=" &
downloadFile

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile downloadPath

Response.BinaryWrite objStream.Read

objStream.Close
Set objStream = Nothing
Response.End
 
D

Derrick

more info, in particular, I can reproduce this, the code below generates a
different size file on the client, the download file on the server is 63.7
MB (66,848,355 bytes), when I download it grows to 63.7 MB (66,851,533
bytes), consistently. ??

Thanks in advance for any help!

Derrick
 
J

Jeff Dillon

I'm doing similar with similar sized files...my code is:

MyFileStream = New FileStream(pathspec & filespec, FileMode.Open)
FileSize = MyFileStream.Length

Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()

Response.BufferOutput = True

Response.ContentType = "application/asp-unknown"

Response.AddHeader("content-disposition", "attachment; filename=" &
filespec)

Response.BinaryWrite(Buffer)

Response.Flush()
Response.End()

Jeff
 
D

Derrick

Jeff, thanks, I looked at yours which appears to be asp.net, rewrote mine a
bit, this modified code downloads the file with the correct size..
interesting, I'm guessing it's the clear and flush around the binary write..

'Set the content type to the specific type that you are sending.
Set objFilesystem =
Server.CreateObject("Scripting.FileSystemObject")
Set objFilestream = objFilesystem.GetFile(downloadPath)
intFilelength = objFilestream.size

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile downloadPath

Response.Clear
Response.ContentType = "octet-stream" '"application/zip"
Response.AddHeader "Content-Disposition", "attachment; filename=" &
downloadFile
Response.AddHeader "Content-Length", intFilelength
Response.BinaryWrite objStream.Read(intFileLength)
Response.Flush
Response.End

objStream.Close
Set objStream = Nothing


Jeff Dillon said:
I'm doing similar with similar sized files...my code is:

MyFileStream = New FileStream(pathspec & filespec, FileMode.Open)
FileSize = MyFileStream.Length

Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()

Response.BufferOutput = True

Response.ContentType = "application/asp-unknown"

Response.AddHeader("content-disposition", "attachment; filename=" &
filespec)

Response.BinaryWrite(Buffer)

Response.Flush()
Response.End()

Jeff

Derrick said:
I have an http download that streams a zip file to client, after
download
I
am getting "Error [file name] start of central directory not found; Zip file
corrupt. Possible casue: file transfer error."

Ring any bells? Here's the asp code, thanks in advance!!

Derrick

...
Response.ContentType = "application/zip"
Response.AddHeader "Content-Disposition", "attachment;
filename="
&
downloadFile

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile downloadPath

Response.BinaryWrite objStream.Read

objStream.Close
Set objStream = Nothing
Response.End
 

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,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top