Research on the method of uploading file in ASP

Source: Internet
Author: User
Tags character set file system file upload ftp ftp client advantage

Absrtact: In the browser-based/server based application environment, uploading various types of files in the browser has been one of the difficult problems in user file management applications. There are three mechanisms for uploading files in http: Rfc1867,put and WebDAV. A common implementation approach is to take advantage of a new type introduced in RFC1867: File and ADO Stream objects. In this paper, the upload method and the realization principle are discussed, and the concrete solution examples are given.

Keyword: ASP component file Object

Currently, applications based on browser/server mode are more popular. When a user needs to transfer files to a server, one of the common methods is to run the FTP server and set the FTP default directory for each user to the user's Web home directory, so that the user can run the FTP client and upload files to the specified Web directory. This requires users to know how to use an FTP client. Therefore, this solution is only feasible for experienced users who are familiar with FTP. If we can integrate the file upload function with the web, so that users can complete the upload task with only a Web browser, this will be very convenient for them. However, since the file System object can only transfer text file limitations, the biggest problem with ASP is the problem of uploading files. Here's how to upload a file in a Web page based on an HTTP protocol.

A Three mechanisms for uploading over HTTP

There are three mechanisms for uploading via http: RFC1867, put, and WebDAV.

Put was introduced in HTTP 1.1 with a new HTTP verb. When the Web server receives an HTTP put and object name, it authenticates the user, receives the contents of the HTTP stream, and stores it directly into the Web server. Because this can cause damage to a Web site, it can also lose the most HTTP advantage: Server programmability. In the case of put, the server handles the request itself: there is no room for CGI or ASP applications to intervene. The only way to get your application to capture put is to operate at the lower level, the ISAPI filter layer. The application of put is limited due to the corresponding reasons.

WebDAV allows distributed authentication and translation of Web content. It introduces several new HTTP verbs that allow uploading via HTTP, locking/unlocking, registering/verifying Web content. The "Save to Web" in Office 2000 is implemented through WebDAV. If all you're interested in is uploading content, WebDAV is a great application and it solves a lot of problems. However, if you need to upload files in your Web application, WebDAV is useless to you. Like the HTTP put, those WebDAV verbs are interpreted by the server, not the Web application. You need to work on these verbs in the ISAPI filtering layer to access WebDAV and interpret the content in your application.

RFC1867 (Http://www.ietf.org/rfc/rfc1867.txt) was eventually accepted by the HTML3.2 as a recommended standard. It's a very simple but powerful idea: Define a new type in a form field.

<INPUT TYPE="FILE">

And in the form itself, a different encoding scheme is added, no longer using the typical:

<FORM ACTION="formproc.asp" METHOD="POST">

Instead use:

<FORM ACTION="formproc.asp" METHOD="POST" ENCTYPE="multipart/form-data">

This coding scheme is much more efficient when it transmits large amounts of data than the default "application/x-url-encoded" form coding scheme. URL encoding has only a limited set of characters, using any character that exceeds the character set, must be replaced with '%nn ', where nn represents the corresponding 2 hexadecimal digits. For example, even ordinary whitespace characters are replaced with '%20 '. RFC1867 uses a multipart MIME encoding, which is not encoded to transmit large amounts of data, as is often seen in e-mail messages, but simply adds a few simple but useful headers around the data. The main browser manufacturers have adopted the recommended "Browse ..." button, users can easily use the local "open file ..." dialog box to select the file to upload.

RFC1867 still leaves the flexible method of uploading most files to your Web application. Put is very limited. WebDAV is useful to authors of content, such as FrontPage users, but is rarely used by web developers who want to add file uploads to a Web application. Therefore, RFC1867 is the best way to add file uploads to a Web application.

In practical applications, Microsoft provides free Posting Acceptor. ASP does not understand the "multipart/form-data" coding scheme. Instead, Microsoft offers Posting acceptor, Posting acceptor an ISAPI application that accepts repost to an ASP page after the upload is complete.

Software Artisans's sa-fileup is one of the earliest commercial Active server components. After several improvements, it is now present as a pure ASP component.

Similar components have been developed in China, such as AspcnUP.dll components developed by http://www.aspcn.com ASP China, and GEUpload10.dll components developed by Yan Cheng Studios (www.greatengine.com).

Two Implementation principle analysis of file uploading based on ASP

The basic principle is: Use ADO Stream object's BinaryRead method to read out all the data in form, intercept the required file data and save it in binary file.

Here is an example of uploading a file page (upload.htm):

<html>
<body>
<form name="Upload" Method="Post" Enctype="multipart/form-data" Action="Upload.asp">
<input type="file" name="FileName">
<INPUT TYPE="Submit" VALUE="Upload"></TD>
</form>
</body>
</html>

Related Article

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.