XML skills file Upload

Source: Internet
Author: User
This document describes an example of using XML to upload files. This example describes how to apply the MSXML3.0 and ADOStream objects to implement this new Upload method. There are many benefits, such

Overview
This article describes an example of using XML to upload files. this method does not have any restrictions in traditional methods. This example describes how to apply the MSXML3.0 and ADO Stream objects to implement this new Upload method. There are many benefits, such as the absence of dedicated Upload components.


Introduction
In order to obtain the upload function in HTML webpages, we can apply the following FORM pattern on the client:

This kind of plan has many restrictions on the client and server applications. First, we must apply the POST method because the GET method cannot process such form data. In addition, there is no way to trigger a POST action without applying a form. After the data is sent to the form processing program, the browser will load the processing program as a new page, and then the application will see a page conversion process that is not desirable.
The ENCTYPE attribute defines the MIME encoding method for the form. The "multipart/form-data" must be applied to the ENCTYPE attribute of the form for file upload ". Setting this attribute as "multipart/form-data" creates a POST buffer (composite structure) that is different from the traditional structure. ASP Request objects cannot access such form content. Therefore, we can use the Request. binaryRead method to visit the data, but we cannot use the script language to complete this. The Request. binaryRead method returns a VTarray-type data (a Variant array containing only one byte of unsigned characters ). However, the scripting language can only process Variant data. To determine the title, you can only use a dedicated ASP Upload component or an ISAPI extended program, such as CPSHOST. DLL. This is a design restriction.

New Upload plan

Follow these steps.
Client:

Use MSXML 3.0 to create an XML document
Create an XML node for binary content
Apply ADO Stream object to put uploaded file data into this node
The XMLHTTP object is used to send this XML document to the Web server.

Server:
Read XML documents from the Request object
Reads data from binary nodes and stores the data in files on the server. Of course, we can also store it in the BLOB field of the database.
Before explaining this code, we can think about this plan.

Thoughts on XML

XML pattern supports many data types, such as numeric, float, and character. Many authors define XML as an ASCII pattern, but we cannot neglect it. XML techniques can also use the "bin. base64" data type to describe binary information. This feature is fully supported by the MS XML3.0 parser, but some special settings are required. This object provides some attributes that can fully control binary data:

Obj_node.dataType-the read/write attribute defines the data type of a specific node. MSXML parser supports more data types (see MSDN: http://msdn.microsoft.com/library/psdk/xmlsdk/xmls3z1v.htm)
For binary data, we can apply the "bin. base64" type.

Obj_node.nodeTypedValue-this read/write attribute contains the data of the specified node according to the specified type.
We can create an XML document that contains multiple bin. base64 nodes and contains uploaded files. This feature can be used to upload multiple files at a time using a POST.

We can use the XMLHttpRequest object and POST method to send an XML document to the Web server. This object provides client protocol support for the HTTP server and promises to send and receive ms xmldom objects on the Web server. XMLHttpRequest is a built-in COM object of Internet Explorer 5 (no custom installation is required), and the page does not need to be converted after sending.


Thoughts on ADO Stream objects

We can create an XML document that contains one or more binary nodes on the client. We must also add the file content to the node. However, unfortunately, the script language cannot visit the local file system, and the Scripting. FileSystem object (which is a built-in object of the Win32 system) cannot visit the binary file until now. This is a design restriction. So we need to find another COM object that can be provided to visit the local binary file.

ADO Stream objects (components in MDAC 2.5) provide a means to read, write, and manage binary Stream data. The content of a byte stream can be text or binary data, and there is no capacity limit. In ADO 2.5, Microsoft's priority on Stream objects does not belong to any layer of the ADO object structure. Therefore, we can apply this object.

In this article, the Stream object is used to visit the file content, and then the content is saved to the XML node.


Client

The following sample code applies Stream and MSXML objects to complete file upload.


File Send


Ready

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.