Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Sending Large File

Reply
Thread Tools

Sending Large File

 
 
PJ
Guest
Posts: n/a
 
      06-24-2003
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(textPt r, 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to stop Outlook sending a large file? Caught NZ Computing 102 10-20-2010 04:38 AM
Re: OverflowError while sending large file via socket Steven D'Aprano Python 1 04-13-2009 01:58 AM
median of large data set (from large file) friend.05@gmail.com Perl Misc 5 04-02-2009 04:06 AM
Why I get OE error in sending large file? Thaqalainnaqvi@gmail.com Computer Support 4 05-12-2006 04:31 AM
Sending large file attachments Ben Deitz Computer Information 2 04-06-2005 03:50 PM



Advertisments