introduction
To get an upload function in an HTML page, we can use the format in the client:
This solution has many restrictions on the use of the client and server. First, we must use the POST method because the GET method cannot handle such form data. Also, there is no way to trigger a POST action without using a form. After sending data to the form handler, the browser will load the handler as a new page, and then the user will see a page conversion process that does not expect.
ENCTYPE Attribute Defines the MIME encoding method for the form. The encType property of the form of the upload file must use "Multipart / Form-Data". Set this property to "Multipart / Form-Data" created a POST buffer (composite structure) different from the traditional structure, the ASP's Request object cannot access such form content. So, we can use the Request.BinaryRead method to access these data, but you can't use the scripting language to complete all. Request.binaryRead method Returns a VTARRAY type data (only a Variant type array of unmanned byte characters). But the scripting language can only handle Variant data. To solve this problem, you can only use a dedicated ASP upload component, or the ISAPI extension, such as cpshost.dll. This is a design restriction.
New uploading plan
The following steps need to be followed.
Client:
Create an XML document using MSXML 3.0
Create an XML node for binary content
Use ADO Stream Object to put uploaded file data into the node
Send this XML document to the web server using the XMLHTTP object
Service-Terminal:
Read the data in the XML document reading the data in the binary node from the Request object and stored in the file on the server. Of course, we can also store them into the BLOB field of the database.
Before explaining this code, we can think about this program.
Think about XML
XML format supports many data types, such as Numeric, Float, Character, and more. Many authors define XML as ASCII formats, but we cannot ignore, XML technology can also use the "bin.base64" data type to describe binary information. This feature is fully supported in the MS XML3.0 parser, but some special settings are required. This object provides some properties that can be fully controlled to binary data:
Obj_node.DataType - This readable and writable property defines the data type of a particular node. MSXML parser supports more data types (see MSDN:
http://msdn.microsoft.com/library/psdk/xmlsdk/xmls3z1v.htm)
For binary data, we can use the "bin.base64" type.
Obj_node.nodetyped
Value - This readable write property contains data in specified nodes represented by the setting type.
We can create an XML document containing multiple bin.base64 type nodes, which contains uploaded files. This feature can use a POST upload multiple files at a time. We can send an XML document to the web server using the XMLHttpRequest object and the POST method. This object provides client protocol support for HTTP servers, allowing MS XMLDOM objects to be sent and accepted on a web server. XMLHttpRequest is a COM object built into Internet Explorer 5 (do not need to be customized), and no conversion page is required after sending.
Thoughts on the ADO stream object
We can create an XML document containing one or more binary nodes on the client. We must also fill the file content into the node. But very unfortunate, the scripting language cannot access the local file system, and
Scripting.FileSystem object (the built-in object of Win32 system) is not available so far. This is a design restriction. So we need to find a COM object that can provide access to local binary files.
ADO Stream objects (components in MDAC 2.5) provide means for reading, writing, and managing binary flow data. The content of the byte stream can be text, or binary data, and there is no limit on capacity. In ADO 2.5, Microsoft's introduction to the Stream object is not any layer of the ADO object structure, so we can use this object without bundling.
This article uses the Stream object to access the file content, and then store the content into the XML node.
Client
The following sample code completes the file upload action using the Stream and MSXML objects.