Large File Downloads - Best method?

T

Tim

I'm using the code below to enable downloads from my site. This works
well for small files, but larger ones (10Mb+) effectively cause the
site to lock up, or run very slowly for all other users. The download
process takes all of the webserver's resources, typically I see the
memory max out.

What is the best way to deal with larger downloads without resorting
to 3rd part components like SA File Upload?

Case "getimage"
If Request.QueryString("thmb") = "y" Then sFld = "Thumbnail"
Else sFld = "Data"
oCMD = New SqlCommand("SELECT Name,Type,Size," & sFld & " FROM
Files WHERE ID = " & Request.QueryString("id") & " AND Acct = " &
SrcAcct, oConn)

' Open the connection and read data into the DataReader.
oConn.Open()
myReader =
oCMD.ExecuteReader(CommandBehavior.SequentialAccess)
myReader.Read()
sName = myReader.GetString(0)
sType = myReader.GetString(1)
'iSize = myReader.GetInt32(2)

' Reset the starting byte for a new BLOB.
startIndex = 0

' Read bytes into outbyte() and retain the number of bytes
returned.
retval = myReader.GetBytes(3, startIndex, outbyte, 0,
bufferSize)

If Request.QueryString("file") = "y" Then
If UCase(sType) = "JPG" Then
Response.ContentType = "image/jpeg"
Else
Response.ContentType = "application/x-" &
sType
End If
Response.Addheader ("Content-Disposition", "filename="
& sName & "." & sType)
'Response.AddHeader ("Content-Length", iSize) This
causes problems every other click.
Response.CacheControl = "public"
Else
Response.ContentType = "image/jpeg"
End If

' Continue reading and writing while there are bytes beyond
the size of the buffer.
Do While retval = bufferSize
Response.BinaryWrite (outbyte)
Response.Flush
' Reposition the start index to the end of the last
buffer and fill the buffer.
startIndex += bufferSize
retval = myReader.GetBytes(3, startIndex, outbyte, 0,
bufferSize)
Loop

' Write the remaining buffer.
Response.BinaryWrite (outbyte)
Response.Flush

' Close the reader and the connection.
myReader.Close()
oConn.Close()

Response.End
 
B

bruce barker

turn page buffering off.

Response.BufferOutput = false;

-- bruce (sqlwork.com)
 
L

Laidbak

What is the best way to deal with larger downloads

I'd personally write a client side ftp upload utility to handle such a task.
It really would not take you more than a few hours to comprehensively write the
code against a 3rd party control (Mabry)...

otherwise, you could roll your own ftp functionality which will take you a little
longer, but it would be worth it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,113
Latest member
Vinay KumarNevatia
Top