473,465 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Large File Downloads - Best method?

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.SequentialAcces s)
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

Nov 18 '05 #1
2 1912
turn page buffering off.

Response.BufferOutput = false;

-- bruce (sqlwork.com)
"Tim" <ti************@hotmail.com> wrote in message
news:k5********************************@4ax.com...
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.SequentialAcces s)
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

Nov 18 '05 #2
>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.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
Wil Moore III, MCP Site : www.quicksitedesign.com?em
Application Developer Site : www.digitallysmooth.com?em
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily...
2
by: Edvard Majakari | last post by:
Hi all ya unit-testing experts there :) Code I'm working on has to parse large and complex files and detect equally complex and large amount of errors before the contents of the file is fed to...
4
by: Dag Sunde | last post by:
Just wondering if anyone have looked into this? How to split up ones JavaScript library? A lot of very specific (and small) .js files, or a few larger files. I'm thinking about load-time...
2
by: Jerry Camel | last post by:
I know I've seen postings on this, but I can't find them anymore... I was able to fix the issue of large uploads by adding <httpRuntime maxRequestLength="1048576" /> to the web.config file. I...
3
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On...
3
by: A.M-SG | last post by:
Hi, I have a ASP.NET aspx file that needs to pass large images from a network storage to client browser. The requirement is that users cannot have access to the network share. The aspx file...
10
by: mwt | last post by:
This code works fine to download files from the web and write them to the local drive: import urllib f = urllib.urlopen("http://www.python.org/blah/blah.zip") g = f.read() file =...
7
by: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= | last post by:
Hi, I have been using the code (some of it has been removed for simplicity) below to allow authenticated (using ASP.NET membership database) users to get a file from their archive area. It...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.