file size mismatch when downloading files...

Discussion in 'ASP General' started by PeterB, Feb 9, 2005.

  1. PeterB

    PeterB Guest

    Hi!

    I am using the script below to download files, that are in a non-public
    directory, from my site. The "smaller files" section works for smaller
    files. However when the files are getting larger, it won't work! I'm not
    sure what the size limit is, or if it is some kind of timeout, which would
    mean very small files if the connection is slow (I'm working against a
    server on the LAN).

    When I try to download larger files with the "small file"-section, I only
    get a fraction (a few bytes) of the file. The "Large files"-section however
    transmitts the file correctly except for a FEW bytes. My testfile is
    16.010.423bytes originally, but downloaded it is 16.009.507 bytes.

    As I am explicitly setting the size of the file in the download I cannot
    understand why this happens?!?

    Server: Win 2003, IIS 6.0
    Client: WinXP SP2

    The code below is partially taken from this page:
    http://www.aspfaq.com/show.asp?id=2161

    First fFileName and fFullPath is set...

    if fs.FileExists(fFullPath)=false then
    Set fs=Nothing
    Response.End
    Else
    Set objFileStream = fs.GetFile(fFullPath)
    intFileLength = objFileStream.Size 'Size of file

    Set adoStream = CreateObject("ADODB.Stream")
    adoStream.Open
    adoStream.Type = 1 'Binary
    adoStream.LoadFromFile(fFullPath)

    '----------------- Larger files ------------------
    If intFileLength > 2000000 Then '~2MB size limit
    Response.Buffer = False
    Server.ScriptTimeout = 30000

    chunk = 2048
    iSz = adoStream.Size

    Response.ContentType = "octet-stream" '"application/zip"
    Response.AddHeader "Content-Disposition", "attachment; filename=" &
    fFileName
    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
    '------------------- Smaller files -----------------
    Else
    Response.Buffer = True
    Server.ScriptTimeout = 30000
    Response.Clear
    Response.ContentType = "octet-stream"
    Response.AddHeader "Content-Disposition","attachment; filename=" &
    fFileName
    Response.AddHeader "Content-Length", intFileLength
    Response.BinaryWrite(adoStream.Read(intFileLength))
    Response.Flush

    adoStream.Close
    Set adoStream = Nothing
    Set objFileStream = Nothing
    Set fs = Nothing

    End If
    End If
    Response.End
     
    PeterB, Feb 9, 2005
    #1
    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. OriginalBrownster
    Replies:
    4
    Views:
    348
    Dennis Lee Bieber
    Aug 21, 2006
  2. tiewknvc9
    Replies:
    6
    Views:
    673
    Chris Uppal
    Oct 1, 2006
  3. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,651
    Michael Jung
    May 25, 2008
  4. Keith Thompson

    Re: File Size - Big File Size

    Keith Thompson, Oct 1, 2009, in forum: C Programming
    Replies:
    6
    Views:
    300
    Phil Carmody
    Oct 3, 2009
  5. S N
    Replies:
    0
    Views:
    243
Loading...

Share This Page