ADODB.stream hangs with some cases of downloading zip files

Discussion in 'ASP General' started by Avi, Apr 8, 2004.

  1. Avi

    Avi Guest

    hello to all the experts,

    The following is a code taken from and ASP file, called
    downloadgivenfile.asp, that uses the adodb.stream class in order to
    download a file from a server. If one wants to download a file, then
    typing http://mywebsite/downloadgivenfile.asp?FileName=myfile.exe
    would prompt the user with a save open message and followed by a
    'save' common dialoog box. Everything works fine with exe files and
    cab files, but when I try to download a zip file, something weird is
    happens. From all the zip files that I tried to download (i.e., .zip
    extension) there very few successes. In those failing cases, I was
    prompted with 'save or open' dialog box, and when I press save it
    hangs forever without any progress in terms of downloading or
    reporting of downloading. If one waits long enough, the an error
    message will appear, saying that the server had to disconnect the
    connection -- i guess the server noticed thah nothing happens so it
    disconnects the connection. In one case where the downmload was
    successful with zip file, I renamed the file adding it another
    character (e.g., changed the file name from myfile.zip to myfile.zip1)
    and the success turned into failure. I did some research on the
    internet for quite some time bu I have not founf any answer to that,
    maybe because I'm not so familiar with the adodb.stream. Actually the
    code you are about to see now is an improvement of some code that
    another user on the internet published to the extent of claiming that
    it can be used to download any file. Here Any assitance in figuring
    out what is going on here an dhow to tackle the problem will be
    greatly appreciated. is the code the populates the ENTIRE asp file:

    Thank you in advance, Avi


    <html>

    <head>
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head>

    <body bgcolor="#33ccff">

    <%
    call DownLoadTheFileInTheQuesryString
    function DownLoadTheFileInTheQuesryString()
    Dim objStream
    RelativeFileNmaePath=Request("FileName")
    ThePath="D:\my new web site\"
    PathPlusFileName=ThePath & RelativeFileNmaePath
    FileName=ReturnFileNameOnlyGivenFilePlusPath(PathPlusFileName)
    IsThereSuchFile=DoesFileExist("D:\my new web site\Company_Packages\"
    & FileName,objFile)
    if IsThereSuchFile=false then
    response.Write "<p>File not found Error</p>"
    else
    Response.Expires = 0
    Response.Buffer = true
    response.clear
    Response.AddHeader "Content-Disposition", "attachment;
    filename=" & FileName
    lSize =objFile.Size
    Response.AddHeader "Content-Length", lSize
    Response.Charset = "UTF-8"
    ThecontentType=ReturnFilterPropertyForCommonDialogControl(FileName)
    Response.ContentType =ThecontentType' "application/zip" '=
    ThecontentType'"application/octet-stream"
    Response.CacheControl = "public"
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = 1
    objStream.LoadFromFile PathPlusFileName
    CHUNK=2048
    NumberofBlocks=(lSize -(lsize mod chunk))/chunk
    For lBlocks = 1 To NumberofBlocks
    If Response.IsClientConnected = False Then Exit For
    Response.BinaryWrite objStream.Read(CHUNK)
    Response.Flush
    Next
    lSize = lSize Mod CHUNK
    If lSize = 0 And Response.IsClientConnected = True Then
    Response.BinaryWrite objStream.Read(lSize)
    Response.Flush

    end if

    objStream.Close
    set objStream = Nothing
    Set objFile = Nothing

    'response.end
    end if
    end function
    function ReturnFilterPropertyForCommonDialogControl(FileExtension)
    select case ucase(FileExtension)
    case "EXE"
    ReturnedValue="Application/exe"
    case "ZIP"
    ReturnedValue="Application/zip"
    end select
    ReturnFilterPropertyForCommonDialogControl=ReturnedValue
    'response.write "<p>" & ReturnedValue & "</p>"
    end function
    function ReturnFileNameOnlyGivenFilePlusPath(PathPlusFileName)
    ISItFirstLoop=true
    PreviosPosition=0
    do while PositionOfForwardSlash<>0 or ISItFirstLoop=true
    ISItFirstLoop=false
    PreviosPosition=PositionOfForwardSlash
    PositionOfForwardSlash= InStr(PositionOfForwardSlash+1,
    PathPlusFileName, "\")

    loop
    ReturnFileNameOnlyGivenFilePlusPath=mid(PathPlusFileName,PreviosPosition+1)
    end function
    Function DoesFileExist(TheFilePlusPath,FileObject)
    Set fso = CreateObject("Scripting.FileSystemObject")
    'msgbox fso.getfile(TheFilePlusPath).size

    DoesFileExist=fso.FileExists(TheFilePlusPath)
    if DoesFileExist=true then set
    FileObject=fso.GetFile(TheFilePlusPath)
    end function
    %>


    </body>

    </html>
     
    Avi, Apr 8, 2004
    #1
    1. Advertising

  2. Hi,

    You should not set this charset and not write ANY HTML content to the
    client. That content, will cause the Content-Length to be incorrect and the
    download will corrupt.


    Response.CharSEt= "utf-8"
    it will cause problems.

    > Response.AddHeader "Content-Disposition", "attachment;
    > filename=" & FileName
    > lSize =objFile.Size
    > Response.AddHeader "Content-Length", lSize
    > Response.Charset = "UTF-8"
    > ThecontentType=ReturnFilterPropertyForCommonDialogControl(FileName)
    > Response.ContentType =ThecontentType' "application/zip" '=
    > ThecontentType'"application/octet-stream"
    > Response.CacheControl = "public"
    > Set objStream = Server.CreateObject("ADODB.Stream")


    Make it CreateObject as well :)
     
    Egbert Nierop \(MVP for IIS\), Apr 9, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley
    Replies:
    1
    Views:
    603
    Andrew Thompson
    Sep 16, 2004
  2. bb2j3z
    Replies:
    1
    Views:
    5,252
    Alexey Smirnov
    Dec 12, 2008
  3. Juan
    Replies:
    10
    Views:
    685
    Alhambra Eidos Kiquenet
    Jul 8, 2008
  4. Kevin Shea

    IE6 hangs with ADODB.Recordset

    Kevin Shea, Jan 21, 2004, in forum: Javascript
    Replies:
    2
    Views:
    120
    Brynn
    Jan 22, 2004
  5. MoshiachNow
    Replies:
    2
    Views:
    276
    Ilya Zakharevich
    Oct 4, 2006
Loading...

Share This Page