Sending Large File
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 =
Response.Buffer = False
Response.ContentType = "application/octet-stream"
'should I set this???
Response.AddHeader("Content-Disposition", "attachment; filename=" +
Dim size As Integer
If offset + buffer > fileItem.ByteCount Then
size = fileItem.ByteCount - offset
size = buffer
Response.BinaryWrite(MyFactory.GetFileChunk(textPt r, offset,
offset += size
Loop Until offset >= fileItem.ByteCount
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?
|All times are GMT. The time now is 12:23 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.