lpenrod
asked on
File is corrupt when downloaded
I have a folder that contains a zip file. If I open the file directly, it opens just fine.
I use this code I found here on EE from Sybe:
sFilePath = "C:\sites\Single44\sam\web root\secre t_folder\C olor Particle Logo.zip"
sContentType = "application/zip"
sDisplayName = "Test download.zip"
Dim oStream
Set oStream = Server.CreateObject("ADODB .Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sFilePath
Response.ContentType = sContentType
Response.AddHeader "Content-Disposition", "attachment; filename=" & sDisplayName
Response.AddHeader "Content-Length", oStream.Size
Response.BinaryWrite oStream.Read
oStream.Close
Set oStream = Nothing
The file downloads, but won't open ("It does not appear to be a valid archive").
The original and downloaded files are the same size.
Not sure what the problem is. Lots of people seem to be using this code with lots of success.
I use this code I found here on EE from Sybe:
sFilePath = "C:\sites\Single44\sam\web
sContentType = "application/zip"
sDisplayName = "Test download.zip"
Dim oStream
Set oStream = Server.CreateObject("ADODB
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sFilePath
Response.ContentType = sContentType
Response.AddHeader "Content-Disposition", "attachment; filename=" & sDisplayName
Response.AddHeader "Content-Length", oStream.Size
Response.BinaryWrite oStream.Read
oStream.Close
Set oStream = Nothing
The file downloads, but won't open ("It does not appear to be a valid archive").
The original and downloaded files are the same size.
Not sure what the problem is. Lots of people seem to be using this code with lots of success.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi:
sFilePath = "C:\sites\Single44\sam\web root\secre t_folder\C olor Particle Logo.zip"
sContentType = "application/zip"
sDisplayName = "Test download.zip"
Dim oStream
Set oStream = Server.CreateObject("ADODB .Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sFilePath
Response.ContentType = sContentType
Response.AddHeader "Content-Disposition", "attachment; filename=" & sDisplayName
' Response.AddHeader "Content-Length", oStream.Size <---- remark this line
Response.BinaryWrite oStream.Read
oStream.Close
Set oStream = Nothing
sFilePath = "C:\sites\Single44\sam\web
sContentType = "application/zip"
sDisplayName = "Test download.zip"
Dim oStream
Set oStream = Server.CreateObject("ADODB
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sFilePath
Response.ContentType = sContentType
Response.AddHeader "Content-Disposition", "attachment; filename=" & sDisplayName
' Response.AddHeader "Content-Length", oStream.Size <---- remark this line
Response.BinaryWrite oStream.Read
oStream.Close
Set oStream = Nothing
ASKER
KB did not apply.
Response.Buffer=True did not fix.
Reming Response.AddHeader "Content-Length", oStream.Size did not fix.
Any more ideas?
Response.Buffer=True did not fix.
Reming Response.AddHeader "Content-Length", oStream.Size did not fix.
Any more ideas?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It wrote a bunch of jibberish in the browser.
ASKER
I changed: mime_type="application/sav e-as"
to: mime_type="application/zip "
Now it prompts me to save, but it is still corrupt.
to: mime_type="application/zip
Now it prompts me to save, but it is still corrupt.
Hi:
if you change the mime_type to /save-as,still have error?
thanks
if you change the mime_type to /save-as,still have error?
thanks
ASKER
It wrote a bunch of jibberish in the browser instead of prompting to download the file.
Just to ensure that the problem lies with the setting of the HTTP headers, please try the code below..
sFilePath = "C:\sites\Single44\sam\web root\secre t_folder\C olor Particle Logo.zip"
sFilePath1 = "C:\sites\Single44\sam\web root\secre t_folder\C opy_Color Particle Logo.zip"
sContentType = "application/zip"
sDisplayName = "Test download.zip"
Dim oStream
Set oStream = Server.CreateObject("ADODB .Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sFilePath
Response.ContentType = sContentType
Response.AddHeader "Content-Disposition", "attachment; filename='" & sDisplayName & "'"
'Response.AddHeader "Content-Length", oStream.Size
Call oStream.SaveToFile(sFilePa th1)
Response.BinaryWrite oStream.Read
oStream.Close
Set oStream = Nothing
Check whether the code is creating a copy of the downloaded file as well as prompting a file download. Try opeing the copy of the zip file just created and see if thats corrupt.
Cheers!
sFilePath = "C:\sites\Single44\sam\web
sFilePath1 = "C:\sites\Single44\sam\web
sContentType = "application/zip"
sDisplayName = "Test download.zip"
Dim oStream
Set oStream = Server.CreateObject("ADODB
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sFilePath
Response.ContentType = sContentType
Response.AddHeader "Content-Disposition", "attachment; filename='" & sDisplayName & "'"
'Response.AddHeader "Content-Length", oStream.Size
Call oStream.SaveToFile(sFilePa
Response.BinaryWrite oStream.Read
oStream.Close
Set oStream = Nothing
Check whether the code is creating a copy of the downloaded file as well as prompting a file download. Try opeing the copy of the zip file just created and see if thats corrupt.
Cheers!
>>It wrote a bunch of jibberish in the browser instead of prompting to download the file.
Try opeing it in a new browser window. Sometimes, after errors have occured, the download code writes jibberish on to the browser :)
Cheers!
Try opeing it in a new browser window. Sometimes, after errors have occured, the download code writes jibberish on to the browser :)
Cheers!
Do you need further assistance with this?
Cheers!
Cheers!
ASKER
Sorry, I have been out of town. I will try this evening.
ASKER
My appologies for taking so long to get back to this...
The file that downloads is corrupt.
The file that is copied in not corrupt, it is fine.
The file that downloads is corrupt.
The file that is copied in not corrupt, it is fine.
ASKER
The original file is 22,311 bytes.
The "Copy_" file is 22,311 bytes.
The downloaded (corrupt) file is 22,347 bytes.
The "Copy_" file is 22,311 bytes.
The downloaded (corrupt) file is 22,347 bytes.
ASKER
OK, opened the downloaded file in notepad and I see HTML code before and after the file.
Surely a simple fix...?
Surely a simple fix...?
ASKER
Yea!
I added:
Response.Clear
Response.Buffer=True
before the line:
Response.ContentType = sContentType
and now it works!
I added:
Response.Clear
Response.Buffer=True
before the line:
Response.ContentType = sContentType
and now it works!
ASKER
You were both exremely helpful. Should I split the points?
Split is fine with me.
Cheers!
Cheers!
http://support.microsoft.com/?kbid=308090
Cheers!