Upload request. totalbytes using the form as a binary file to extract the uploaded second-level data.

Source: Internet
Author: User

Copy codeThe Code is as follows: <input name = "file" type = "file">
Formsize = request. totalbytes
Formdata = request. binaryread (formsize)
Bncrlf = chrB (13) & chrB (10)
Divider = leftB (formdata, clng (partition B (formdata, bncrlf)-1)
Datastart = instrb (formdata, bncrlf & bncrlf) + 4
Dataend = Consumer B (datastart + 1, formdata, divider)-datastart
Mydata = midb (formdata, datastart, dataend)

Formsize = request. totalbytes
Obtains the maximum number of bytes for upload.
-----------------------
Formdata = request. binaryread (formsize)
Get form data of binary stream
-----------------------
Bncrlf = chrB (13) & chrB (10)
Set the crlf carriage return line code variable
------------------------------
Divider = leftB (formdata, clng (partition B (formdata, bncrlf)-1)
Obtain the byte data on the left of the first crlf.
When B (formdata, bncrlf)-1 checks to find that the bit value of the crlf binary byte is reduced by one, that is, the binary data before the flag bit information. It must be noted that when B returns clng, therefore, adding a clng here is redundant.
------------------------------
Datastart = instrb (formdata, bncrlf & bncrlf) + 4
Obtain the image data and remove the start position of the header information added to the form, that is, your type = file starts from the byte position of the real file data after the form is submitted.
The position of two consecutive crlf + 4 (that is, the length of a crlfg)
-------------------------------
Dataend = Consumer B (datastart + 1, formdata, divider)-datastart
The position of the obtained data + 1 is used as the reference calculation value for checking the end of the data. The first binary form separator header information is returned at the position starting with datastart + 1, subtract the relative location of datastar.
----------------------------
Mydata = midb (formdata, datastart, dataend)
Midb () obtains the star end-bit data of the uploaded file data obtained after multiple twists and turns.
OK --------------> the uploaded second-level data is extracted cleanly.

Note:
(1). All * B series VB functions are processed by byte. They must be used to process the second-level system.
(2). type = file and form data of the corresponding form type are appended with the corresponding header information for each file field after submission.
Therefore, you must use the above algorithm to clearly find the real file data.
(3) At the same time, the header information also contains the data uploaded to the initial file name, such as c: \ aaa \ aaa.jpg. You can also process formdata and extract the initial file name of the data in this file domain.
(4) These algorithms are derived from the format data provided by the http "form" Specification, so any processing algorithm is similar!

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.