Using XML to help upload files

Source: Internet
Author: User
Author Marco Nanni
Overview
This article explains an example of uploading files using XML technology, and there are no limitations in the traditional approach.
This example describes how to use the MSXML3.0 and ADO stream objects to implement this new upload method. There are a lot of benefits, for example, not needing a dedicated upload component.

Introduction
In order to obtain the upload function in the HTML webpage, we can use the form in the following format in the client:
<form name= "MyForm"
action= "Targeturl.asp"
Enctype= "Multipart/form-data"
Method= "POST" >
<input type= "File" name= "MyFile" >
<input type= "Submit" value= "Upload File" >
</FORM>
This scenario has many limitations on both the client and server side. First, we must use the Post method, because the Get method cannot process such form data. Also, there is no way to raise a post action without using the form. Once the data is sent to the form handler, the browser will load the handler as a new page, and the user will see a page conversion process that is not pleasing to the person.
The Enctype property defines MIME encoding for the form, and the Enctype property of the form that uploads the file must use "Multipart/form-data". Setting this property to "Multipart/form-data" creates a post buffer (composite structure) that differs from the traditional structure, and the ASP's request object cannot access such form content. So we can use the Request.BinaryRead method to access this data, but we can't do it with scripting language. The Request.BinaryRead method returns a Vtarray type of data (a Variant array containing only unsigned byte characters). However, the scripting language can only handle variant types of data. To solve this problem, you can only use a dedicated ASP upload component, or an ISAPI extender, such as CPSHOST.DLL. This is a design limitation.

New upload Scheme
You need to follow the steps below.
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 this node
Use the XMLHTTP object to send this XML document to the Web server
Server side:
To read an XML document from the Request object
Reads the data from a binary node and stores it in a file on the server. Of course, we can also store it in a blob-type field in the database.
Before we explain this code, we can do some thinking about the program.

The thinking of XML
XML Formats support many types of data, such as numeric, float, character, and so on. Many authors define XML as ASCII format, but we cannot ignore that XML technology can also use "bin.base64" data types to describe binary information. This feature is fully supported in Ms XML3.0 resolution, but some special settings are still required. This object provides a number of properties that can be fully controlled for binary data:

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.