Sending Large File

Discussion in 'ASP .Net' started by PJ, Jun 24, 2003.

  1. PJ

    PJ Guest

    I have the following code snippet to send a file stored as an image data
    type from sql server:

    Protected Sub StreamFile(ByVal fileItem As MyFile)
    Dim offset As Integer
    Dim buffer As Integer = 8192
    Dim textPtr As System.Data.SqlTypes.SqlBinary =
    MyFactory.GetFilePtr(fileItem.ID, FileScale.Original)

    Response.Clear()
    Response.Buffer = False
    Response.ContentType = "application/octet-stream"
    'should I set this???
    'Response.AddHeader("Content-Length", fileItem.ByteCount.ToString())
    Response.AddHeader("Content-Disposition", "attachment; filename=" +
    fileItem.Name)
    Response.Flush()

    Dim size As Integer
    Do
    If offset + buffer > fileItem.ByteCount Then
    size = fileItem.ByteCount - offset
    Else
    size = buffer
    End If
    Response.BinaryWrite(MyFactory.GetFileChunk(textPtr, offset,
    fileItem.ByteCount))
    Response.Flush()
    offset += size
    Loop Until offset >= fileItem.ByteCount
    End Sub

    This seems to be working, but I would like to make sure I am doing
    everything as effeciently as possible. My understanding is that the
    ..Flush() method will send the current contents of the response to the
    client. My understanding of the internals of the actual HTTP response(s) is
    a bit weak. Is my loop creating sending a new response during each
    iteration? If this is the case do the headers need to be set again or does
    it simply use the current settings for the headers? Should I set the
    "Content-Length" header? If so, should I set it's value to that of the
    total byte count of the file or to the size of each flushed response? And
    in general...is there a better way to do this?

    TIA~ PJ
     
    PJ, Jun 24, 2003
    #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. Ron Vecchi
    Replies:
    6
    Views:
    509
    Ron Vecchi
    Oct 23, 2003
  2. BVM
    Replies:
    5
    Views:
    1,042
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  3. Steven D'Aprano
    Replies:
    1
    Views:
    477
    Benjamin Peterson
    Apr 13, 2009
  4. Ketchup
    Replies:
    1
    Views:
    273
    Jan Tielens
    May 25, 2004
  5. Replies:
    5
    Views:
    948
    Xho Jingleheimerschmidt
    Apr 2, 2009
Loading...

Share This Page