In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to upload files using XML technology. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Xml technology uploads files
Type: XML/Biztalk
Overview
This article shows an example of uploading files using XML technology without the limitations of traditional methods. This example shows how to use MSXML3.0 and ADO Stream objects to implement this new upload method. There are many benefits, for example, there is no need for dedicated upload components.
Introduction
In order to get the upload function in HTML web pages, we can use FORM in the following format on the client side
< FORM NAME="myForm" ACTION="TargetURL.asp" ENCTYPE="multipart/form-data"METHOD="post" > < INPUT TYPE="file" NAME="myFile" > < INPUT TYPE="submit" VALUE="Upload File" > < /FORM >There are many restrictions on the use of this scheme on both the client and the server side. First, we must use the POST method, because the GET method cannot handle such form data. Also, there is no way to raise a POST action without using a form. After sending the data to the form handler, the browser will load the handler as a new page, and the user will see an unpleasant page conversion process.
The ENCTYPE attribute defines the MIME encoding for the form, and the ENCTYPE attribute of the form uploading the file must use "multipart/form-data". Setting this property to "multipart/form-data" creates a POST buffer (composite structure) that is different from the traditional structure, and the Request object of ASP cannot access such form content. So, we can use the Request.binaryRead method to access this data, but we cannot use a scripting language to do all this. The Request.binaryRead method returns a VTarray type data (a variable-type array containing only unsigned one-byte characters). But scripting languages can only handle variable data. To solve this problem, you can only use a dedicated ASP upload component or an ISAPI extension, such as CPSHOST.DLL. This is a design limitation.
New upload scheme
You need to follow these steps.
Client:
Create an XML document using MSXML 3.0
Create a 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:
Read the XML document from the Request object read the data in the binary node and store it in a file on the server. Of course, we can also store it in the blob field of the database.
Before we explain this code, we can do some thinking about this scenario.
Thinking about XML
XML format supports many data types, such as numeric, float, character, and so on. Many authors define XML as ASCII format, but we can't overlook the fact that XML technology can also use the "bin.base64" data type to describe binary information. This feature is fully supported in MS XML3.0 parsers, but some special settings are needed for now. This object provides some properties that have complete control over binary data:
Obj_node.dataType-this readable attribute defines the data type of a particular node. The 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.nodeTypedValue-this read-write attribute contains data for the specified node represented by the specified type.
We can create an XML document that contains multiple bin.base64 type nodes that contain the uploaded file. This feature allows you to upload more than one file at a time using one POST.
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 the HTTP server, allowing MS XMLDOM objects to be sent and received on the Web server. XMLHttpRequest is a built-in COM object in Internet Explorer 5 (no custom installation is required), and there is no need to convert the page after sending it.
Thinking about ADO Stream object
We can create an XML document on the client side that contains one or more binary nodes. We must also fill the contents of the file into the node. Unfortunately, scripting languages do not have access to the local file system, and Scripting.FileSystem objects (which are built-in to Win32 systems) have so far failed to access binaries. This is a design limitation. So we need to find another COM object that provides access to local binaries.
ADO Stream objects (components in MDAC 2.5) provide the 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 introduction to the Stream object does not belong to any layer of the ADO object structure, so we can use it without bundling.
In this article, you use the Stream object to access the contents of the file, and then store the contents in the XML node.
Client
The following sample code uses the Stream and MSXML objects to complete the file upload action.
< HTML > < HEAD > < TITLE >File Send
< /TITLE > < /HEAD > < BODY > < INPUT id=btn_send name="btn_send" type=button value="FILE SEND" > < DIV id=div_message >Ready
< /BODY > < /HTML > < SCRIPT LANGUAGE=javaScript >/ / upload function function btn_send.onclick () {/ / create ADO-stream object var ado_stream = new ActiveXObject ("ADODB.Stream"); / / create XML document var xml_dom = new ActiveXObject ("MSXML2.DOMDocument") containing default header information and root node; xml_dom.loadXML (''); / / specify data type xml_dom.documentElement.setAttribute ("xmlns:dt", "urn:schemas-microsoft-com:datatypes") / / create a new node, set it to binary data node var l_node1 = xml_dom.createElement ("file1"); l_node1.dataType = "bin.base64"; / / Open the Stream object and read the source file ado_stream.Type = 1; / / 1=adTypeBinary ado_stream.Open (); ado_stream.LoadFromFile ("c:\\ tmp\\ myfile.doc"); / / store the file contents in the XML node l_node1.nodeTypedValue = ado_stream.Read (- 1) / /-1=adReadAllado_stream.Close (); xml_dom.documentElement.appendChild (l_node1); / / you can create multiple binary nodes to upload multiple files at a time / / send XML documents to the Web server var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP"); xmlhttp.open ("POST", ". / file_recieve.asp", false); xmlhttp.send (xml_dom); / / display the information returned by the server div_ messagexss [clean] = xmlhttp.ResponseText }
< /SCRIPT >Server side
The following code uses the same object to provide server-side upload processing.
< %@ LANGUAGE=VBScript% > < % Option ExplicitResponse.Expires = 0 ' 定义变量和对象。dim ado_streamdim xml_domdim xml_file1' 创建 Stream 对象set ado_stream = Server.CreateObject("ADODB.Stream")' 从Request对象创建 XMLDOM对象set xml_dom = Server.CreateObject("MSXML2.DOMDocument")xml_dom.load(request)' 读出包含二进制数据的节点set xml_file1 = xml_dom.selectSingleNode("root/file1")' 打开Stream对象,把数据存入其中 ado_stream.Type = 1 ' 1=adTypeBinary ado_stream.open ado_stream.Write xml_file1.nodeTypedValue' 文件存盘ado_stream.SaveToFile "c:\tmp\upload1.doc",2 ' 2=adSaveCreateOverWrite ado_stream.close' 销毁对象 set ado_stream = Nothing set xml_dom = Nothing' 向浏览器返回信息Response.Write "Upload successful!"% >You can also use the Stream object to put data into blob fields in the database.
Benefits of using this method
Does not cause page conversion.
No dedicated components are required.
You can upload multiple files at the same time.
This program is written in pure script and can be easily inserted into other code without the cooperation of any HTML objects. You can also implement this logic in any language that supports the COM standard.
System security considerations
This method can only be used on internal networks because it requires the security level of IE5 to be set to "low". Must:
Allow scripts and ActiveX objects. This setting allows browsers to execute something like "myobj = new activexobject (...)" The JScript statement of
Access to the data source must be allowed across domains. This setting allows the use of Stream objects on the client side. MS XML DOM 3.0 and MDAC 2.5 must also be installed on both the server and the client.
Thank you for reading! On "how to use XML technology to upload files" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un