Excellent time and space performance ASP non-component upload class

Source: Internet
Author: User
Upload | no component | performance | upload | no components | Performance in decoding speed, Transformation 2.0 is already very high, but it also has the following two problems:
1, with Data_5xsoft. Write Request.BinaryRead (request.totalbytes) reads all data at once and uses RequestData =data_5xsoft. Read all the data at once, in the upload data is too large, will be due to insufficient memory, resulting in upload failure, this should be used in segmented reading mode.
2, save the data, you need to first copy from the Data_5xsoft to a temporary stream, in the preservation of large files, need twice times the storage resources, in a stand-alone state test, you can find that save time with the size of the file increase dramatically, or even more than upload and decoding time.
I write this class, used in the decoding process, block reading (note: block size and speed is not proportional to, stand-alone test shows that 64K block than 1M block much faster) method to solve the problem 1, while the use of ordinary data, write workflow, the contents of the file directly to the file itself, the flow of the way, Solve the problem 2.
The code is as follows and is similar to transformation:
Server.ScriptTimeout = 600
Class Quickupload
Private Fform, Ffile, Upload_stream, Convertstream

Property Get Form
Set Form = Fform
End Property

Property Get File
Set File = Ffile
End Property

Private Sub Class_Initialize
Dim IStart, Iend, boundary, FieldName, FileName, ContentType, Itemvalue, Thefile, Lineend

Set Fform=createobject ("Scripting.Dictionary")
Set Ffile=createobject ("Scripting.Dictionary")
Set Upload_stream=createobject ("ADODB.stream")
Upload_stream.mode=3
Upload_stream.type=1
Upload_stream.open
Set convertstream = Server.CreateObject ("ADODB.stream")
Convertstream.mode =3
convertstream.charset= "GB2312"

If Request.totalbytes<1 then Exit Sub

' DStart = CDBL (Time)

' Find the first boundary
IStart = Search (Upload_stream, ChrB () &AMP;CHRB (10), 1)
' Take the boundary string
Boundary = subString (1, iStart-1, false)
' is not an end boundary, the loop
Do While StrComp (SubString (IStart, 2, false), ChrB &AMP;CHRB (10)) =0
IStart = istart+2
' Fetch table Single message header
Do While True
Iend = Search (Upload_stream, ChrB (&AMP;CHRB), IStart)
' Decomposition information header
line = subString (IStart, Iend-istart, True)
' Move position
IStart = iend+2
If line= "" Then Exit do
pos = InStr (Line, ":")
If Pos>0 Then
If StrComp (left (line,pos-1), "Content-disposition", 1) =0 Then
' Fetch table Item name
FieldName = Extractvalue (line,pos+1, "name")
' Fetch file name
filename = Extractvalue (line,pos+1, "filename")
' Delete file path
filename = Mid (filename,instrrev (filename, "\") +1)
ElseIf StrComp (Left (line,pos-1), "Content-type", 1) =0 Then
' Fetch file type
ContentType = Trim (Mid (line,pos+1))
End If
End If
Loop
' Take the form individual contents
If filename<> "" Then
' New file contents
Set thefile = new FileInfo
Thefile.init FileName, ContentType
' File flow content moved to file stream
Movedata Upload_stream, Thefile.stream, IStart
' Uploading data directly into the file stream can reduce file storage time
Iend = Search (Thefile.stream, boundary, 1)
' Subsequent data moved into the workflow
Movedata Thefile.stream, Upload_stream, iEnd-2

Ffile.add FieldName, Thefile
' Move position
IStart = Istart+2+lenb (boundary)
Else
' Find boundaries
Iend = Search (upload_stream, boundary, IStart)
' Take the form individual contents
Itemvalue = subString (IStart, Iend-2-istart, True)

If Fform.exists (FieldName) Then
Fform.item (FieldName) &AMP;NB



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.