RFC1867 HTTP File Upload
RFC1867 is the "Browse ..." button of the standard definition of "". It introduced the INPUT field type= "File", which is that button, and also specified a multipart form encoding WHI CH is capable of encapsulating files for upload along and all the other fields on an upload form. ( ability to encapsulate file uploads in the upload form and all him field . )
: Specifies the encoding of the combined form
it ' s not easy-to-find documentation on how to work with this stuff, though. Partly this was because if you ' re writing a Perl CGI it's really rather easy-to-work with, and partly it's due to the fact That is, Microsoft IIS ASP doesn ' t (exactly) support RFC1867 file upload. So on the one hand the unixheads think it's too trivial to document and while the ASP script kiddies think that file upload I s the exclusive preserve of genius and guru alike. I.e Bill doesn ' t think you need to use it.
If that last sounds overly bitter, it's because I just finished up a really horrible job that involved uploading files to An IIS server. It would has been nice had somebody at Microsoft found file upload a sufficiently significant function to design Competen tly. As it is, IIS 5.0 now provides a "request.readbinary" method which gives you the whole Request in plaintext, and graciously Allows you to design your own object to read it. Note that the VBS has a ability to read this binary data.
So let's assume for the time being this you ' re working with some reasonable non-iis server. How does really deal with file upload? It turns out to being easy. First, you design your form so that it'll actually do an upload. In short, does this:
enctype=multipart/form-data> type= "file"></form>
In case you were wondering, the standard encoding type for a form are application/x-www-form-urlencoded, and if you leave T He multipart enctype out of your form, then Netscape, for one, would not upload the file, it ' ll just include the filename. If that's what you actually want, this is pretty useful. (However, the RFC leaves behavior in this situation undefined, so you shouldn ' t rely on any particular behavior. I Haven ' t looked to see what IE does in this situation. Undoubtedly something different.)
So this much information I already knew going to my horrible project, or at least knew of it. That's why I assumed that the server end is just as simple. And as I mentioned, in Perl it isn ' t much more difficult than retrieving normal posted data is already. It's just that the IIS doesn ' t support multipart/form-data posts, that's all. Oh, Microsoft has a solution of sorts, called the Something-or-other Manager, and IIS 5.0 are so powerful it this manager Thingy is now included right in the service pack with, gee, at least a kilobyte of documentation.
Yeesh. I ' M off-track again, aren ' t I?
OK, so if this post is gets to the server, what is the does it look like? Well, first of all the Content-type header of the request are set to
multipart/form-data; boundary=[some stuff]
This is what you can ascertain that you ' re really dealing with a properly encoded upload post. The boundary value is probably of the form--------------------------------1878979834, where the digits is randomly gener Ated. This boundary is a MIME boundary; It's guaranteed not to appear anywhere in the data except between the multiple parts of the data.
The data itself appears in blocks is made up of lines separated by cr/lf pairs. It looks like this, more or less:
-------------------------------18788734234content-disposition:form-data; name= "Nonfile_field"value Here-------------------------------18788734234content-disposition:form-data; name= "myfile"; filename= "Ad.gif "Content-type:image/gif[ooh--File contents!] -------------------------------18788734234--
As can see, this post is ' t ' from the form I listed above, because I threw in a non-upload field just to show what it l Ooks like. Anyway, you can see where everything is. Note that you get the originating local filename of the "document for free" in this format, meaning. Develop a document management system. Actual implementation is a exercise for the reader. I'll write more later on the topic, especially if you ask me any questions. Hint, Hint.
So-a Perl reader for this guy was simple:you iterate on the lines of the input and break on your boundary. Do things with the parts as you find them. I have an extensive example so can read and use, which can see here. It works (I-M using it daily) and it ' s well-documented.
And thus concludes the lesson for today. Go forth and upload files.
Http://www.vivtek.com/rfc1867.html
RFC1867 HTTP File Upload