The file size can be controlled. Download name: single block data size: single block data interval and MIME type are easy to use.
Public Shared Function responsefile () Function Responsefile ( Byval _ Request As Httprequest, Byval _ Response As Httpresponse, Byval _ Filename As String , Byval _ Fullpath As String , Byval Blocksize As Long , Byval Sleep As Integer , Optional Byval Mimetype As String = " Application/octet-stream " ) As Boolean
Try
Dim Myfile As New Filestream (_ fullpath, filemode. Open, fileaccess. Read, fileshare. readwrite)
Dim BR As New Binaryreader (myfile)
Try
_ Response. addheader ( " Accept-ranges " , " Bytes " )
_ Response. Buffer = False
Dim Filelength As Long = Myfile. Length
Dim Startbytes As Long = 0
If ( Not _ Request. headers ( " Range " ) Is Nothing ) Then
_ Response. statuscode = 206
Dim Range () As String = _ Request. headers ( " Range " ). Split ( " =- " . Tochararray)
Startbytes = Convert. toint64 (range ( 1 ))
End If
_ Response. addheader ( " Content-Length " , (Filelength - Startbytes). tostring ())
If (Startbytes <> 0 ) Then
_ Response. addheader ( " Content-Range " , String . Format ( " Bytes {0}-{1}/{2} " , Startbytes, filelength - 1 , Filelength ))
End If
_ Response. addheader ( " Connection " , " Keep-alive " )
_ Response. contenttype = Mimetype
_ Response. addheader ( " Content-Disposition " , " Attachment; filename = " + Httputility. urlencode (_ filename, system. Text. encoding. utf8 ))
BR. basestream. Seek (startbytes, seekorigin. Begin)
Dim Maxcount As Integer = CINT (Math. Floor (filelength - Startbytes) / Blocksize) + 1 )
For I As Integer = 0 To Maxcount - 1
If _ Response. isclientconnected Then
_ Response. binarywrite (Br. readbytes (blocksize ))
Thread. Sleep (sleep)
Else
I = Maxcount
End If
Next
Catch Ex As Exception
Return False
End Try
Catch Ex As Exception
Return False
End Try
End Function