ASP/VBScript source code to download of very large files using ASP. The download size is not limited by 2GB or 4GB of size, you can download files with any size, 10th of gigabytes or more.
The sample uses Response.BinaryWrite. Remember that IIS6 has a strong memory leak, so this code does not work with Windows 2003 SP1, you need Windows 2003 SP2 at least. The code works also with other versions of IIS (IIS1-5, IIS7) See also
Experience high memory usage in the W3wp.exe process
Memory leaks may occur when the BinaryWrite method is called
Several browsers (IE, Firefox) or http clients (winhttp) has a download size limit of 2GB or 4GB. See http download over 2GB, 4GB - browser and server behavior
|ASP gigabyte download - download over 2GB, 4GB, very large/huge files.|
<% SendFileByBlocks "Z:\muzikal\pokus.mpg", &H10000 '********************************** SendFileByBlocks ********************************** Sub SendFileByBlocks(FileName, BlockSize) 'Set a time required for download to ScriptTimeout Server.ScriptTimeout = 1200 'CreateObject("ScriptUtils.Thread").Priority = -15 Dim FileSize, ByteCounter FileSize = GetFileSize(FileName) 'Switch off buffer. Response.Buffer = False 'This is download Response.ContentType = "application/x-msdownload" 'Set file name Response.AddHeader "Content-Disposition", _ "attachment; filename=""" & GetFileName(FileName) & """" 'Set Content-Length (ASP doen not set it when Buffer = False) Response.AddHeader "Content-Length", FileSize 'Response.CacheControl = "no-cache" Dim BA: Set BA = CreateObject("ScriptUtils.ByteArray") 'Loop through file contents. For ByteCounter = 1 To FileSize Step BlockSize 'Do not write data when client is disconnected If Not Response.IsClientConnected() Then Exit For 'Read block of data from a file BA.ReadFrom FileName, ByteCounter, BlockSize 'Write the block to output. Response.BinaryWrite BA.ByteArray Next 'CreateObject("ScriptUtils.Thread").Priority = 0 End Sub 'This function returns a file size as a 64bit number Function GetFileSize(FileName) Dim Kernel On Error Resume Next Set Kernel = CreateObject("ScriptUtils.Kernel") GetFileSize = Kernel.GetFileSize(FileName) If IsEmpty(GetFileSize) Then GetFileSize = CreateObject("scripting.filesystemobject").GetFile(FileName).Size End If If IsEmpty(GetFileSize) Then GetFileSize = 0 On Error Goto 0 End Function 'get a file name from the full file path Function GetFileName(FullPath) Dim Pos, PosF PosF = 0 For Pos = Len(FullPath) To 1 Step -1 Select Case Mid(FullPath, Pos, 1) Case ":", "/", "\": PosF = Pos + 1: Pos = 0 End Select Next If PosF = 0 Then PosF = 1 GetFileName = Mid(FullPath, PosF) End Function %>
COM API for calling some of Kernel32 functions.
Huge ASP upload is easy to use, hi-performance ASP file upload component with progress bar indicator. This component lets you upload multiple files with size up to 4GB to a disk or a database along with another form fields. Huge ASP file upload is a most featured upload component on a market with competitive price and a great performance . The software has also a free version of asp upload with progress, called Pure asp upload , written in plain VBS, without components (so you do not need to install anything on server). This installation package contains also ScriptUtilities library. Script Utilities lets you create hi-performance log files , works with binary data , you can download multiple files with zip/arj compression, work with INI files and much more with the ASP utility.
© 1996 - 2011 Antonin Foller, Motobit Software | About, Contacts | e-mail: firstname.lastname@example.org