sending HUGE file to client via Response.BinaryWrite

Discussion in 'ASP General' started by Zam, Mar 10, 2005.

  1. Zam

    Zam Guest

    Hello World,

    Under Windows 2003 Server. IIS6.

    The following code working fine for small files, and for files with size
    about few megabytes.

    If I am trying to send HUGE file -- about 700 Megabyte -- w3wp.exe eat all
    memory (I have 1024 megabytes) and all CPU time without positive result.

    Question: how could i _clever_ and fast send very huge file to client, with
    keeping "file location privacy" ?

    <%
    Response.Buffer = False
    Server.ScriptTimeout = 30000

    Response.ContentType = "application/x-unknown"
    fn = "movie1.avi"
    FPath = "g:\movies\" & fn
    Response.AddHeader "Content-Disposition", "attachment; filename=" & fn

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

    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
    %>

    With best regards,
     
    Zam, Mar 10, 2005
    #1
    1. Advertisements

  2. Zam

    Mark Schupp Guest

    Not familiar with streams so this is mostly a guess but you might try making
    sure that the stream's "mode" is set to adModeRead (=1).

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Zam" <> wrote in message
    news:...
    > Hello World,
    >
    > Under Windows 2003 Server. IIS6.
    >
    > The following code working fine for small files, and for files with size
    > about few megabytes.
    >
    > If I am trying to send HUGE file -- about 700 Megabyte -- w3wp.exe eat all
    > memory (I have 1024 megabytes) and all CPU time without positive result.
    >
    > Question: how could i _clever_ and fast send very huge file to client,

    with
    > keeping "file location privacy" ?
    >
    > <%
    > Response.Buffer = False
    > Server.ScriptTimeout = 30000
    >
    > Response.ContentType = "application/x-unknown"
    > fn = "movie1.avi"
    > FPath = "g:\movies\" & fn
    > Response.AddHeader "Content-Disposition", "attachment; filename=" & fn
    >
    > Set adoStream = CreateObject("ADODB.Stream")
    > chunk = 2048
    > adoStream.Open()
    > adoStream.Type = 1
    > adoStream.LoadFromFile(FPath)
    >
    > 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
    > %>
    >
    > With best regards,
    >
    >
     
    Mark Schupp, Mar 10, 2005
    #2
    1. Advertisements

  3. Zam

    Zam Guest

    Hello Mark,

    Unfortunatly, the same negative result (eat all RAM and CPU time):

    Error number: -2147024882
    Error description: Not enough storage is available to complete this
    operation.

    Error line: adoStream.LoadFromFile(FPath)

    With best regards,

    "Mark Schupp" <> wrote in message
    news:...
    > Not familiar with streams so this is mostly a guess but you might try

    making
    > sure that the stream's "mode" is set to adModeRead (=1).
    >
    > --
    > Mark Schupp
    > Head of Development
    > Integrity eLearning
    > www.ielearning.com
    >
    >
    > "Zam" <> wrote in message
    > news:...
    > > Hello World,
    > >
    > > Under Windows 2003 Server. IIS6.
    > >
    > > The following code working fine for small files, and for files with size
    > > about few megabytes.
    > >
    > > If I am trying to send HUGE file -- about 700 Megabyte -- w3wp.exe eat

    all
    > > memory (I have 1024 megabytes) and all CPU time without positive result.
    > >
    > > Question: how could i _clever_ and fast send very huge file to client,

    > with
    > > keeping "file location privacy" ?
    > >
    > > <%
    > > Response.Buffer = False
    > > Server.ScriptTimeout = 30000
    > >
    > > Response.ContentType = "application/x-unknown"
    > > fn = "movie1.avi"
    > > FPath = "g:\movies\" & fn
    > > Response.AddHeader "Content-Disposition", "attachment; filename=" &

    fn
    > >
    > > Set adoStream = CreateObject("ADODB.Stream")
    > > chunk = 2048
    > > adoStream.Open()
    > > adoStream.Type = 1
    > > adoStream.LoadFromFile(FPath)
    > >
    > > 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
    > > %>
    > >
    > > With best regards,
    > >
    > >

    >
    >
     
    Zam, Mar 11, 2005
    #3
    1. Advertisements

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. Charlie@CBFC
    Replies:
    1
    Views:
    3,026
    Arlyn
    May 13, 2005
  2. Replies:
    1
    Views:
    516
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jun 1, 2006
  3. Replies:
    1
    Views:
    1,040
  4. MichiMichi
    Replies:
    1
    Views:
    911
    MichiMichi
    Mar 1, 2007
  5. Chris  Ashley
    Replies:
    1
    Views:
    750
    bruce barker
    Oct 2, 2007
  6. Replies:
    3
    Views:
    786
  7. senglory
    Replies:
    0
    Views:
    1,219
    senglory
    Jan 24, 2011
  8. twiggy182
    Replies:
    5
    Views:
    426
    twiggy182
    Jan 5, 2007
Loading...