Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

html - Multipart upload form: Is order guaranteed?

It appears that when I use an html form to make a "Content-Type: multipart/form-data" POST request, the fields always appear in the order in which they are listed in the HTML. In practice, do all browsers do this?

The primary motivation for wanting to know this is so I can do server-side validation of form data w/o being required to cache the entire HTTP request in RAM | disk first.

I know CGI, PHP, etc typically won't do anything 'til the upload completes. Probably because RFC 2388 section 5.5 addresses this issue by saying the order is not defined. I'm working w/ a highly customized fork of thttpd and handling the upload w/ C code built right into the server. So I don't care what most servers do.

What I want to know, is if I go out on a limb and assume an order, will I get burned by that assumption?

Take this form for example:

  <form id="formUpload"
        target = "uploadTarget"
        method = "post"
        action = "/bin/upload"
        enctype= "multipart/form-data" >
    <input type="hidden" id="inUser" name="user" />
    <input type="hidden" id="inDest" name="dest"/>
    <input type="file" id="inFile" name="file" />
    <input type="button" value="Upload" onclick="uploadFile();" />
    <iframe id="uploadTarget" name="uploadTarget" src="" style="width:0;height:0;border:0px"/>
  </form>

The 'uploadFile()' function will fill in the user & dest fields before invoking submit(). I would like to validate user & dest server side as well, before recv()-ing the entire HTTP request body.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes:

The parts are sent to the processing agent in the same order the corresponding controls appear in the document stream. Part boundaries should not occur in any of the data; how this is done lies outside the scope of this specification.

http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...