Performance with Multipart/form-data

Asked

Viewed 1,011 times

10

Regardless of the language used on the server side (php, Asp, jsf, etc), there is some problem with adding the attribute enctype="multipart/form-data" whether or not on page forms nay upload?

Because I use template (template) in an application and the form tag is in the template. As only a few pages upload, the attribute will appear on all pages, even those that do not upload.

3 answers

5

The attribute enctype is responsible for defining how the data of the forms will be encoded when they are submitted, and also only works with the POST.

There are currently 3 values that can be specified in this attribute:

  • application/x-www-form-urlencoded
  • Multipart/form-date
  • text/Plain

The application/x-www-form-urlencoded is the default value for the enctype if none is specified, and if in use, all characters are encoded before being sent.

Where a multipart/form-data as a value for this attribute, no character is encoded. This type of request contains several parts, and each part of this request contains a content-diaposition with the guy form-data, and with an additional parameter name whose value is the name of the field.

Finally has the text/plain that converts the spaces into +, but does not encode anything.

According to RFC-2388 Each part of a multipart/form-data must have a content type. In cases where the field is a text, the input character set indicates which encoding to use.

RFC-2388 - 4.5 - For example, a form with a text field in which a user typed 'Joe should 100 "where the euro symbol may have returned form data As:

--AaB03x
content-disposition: form-data; name="field1"
content-type: text/plain;charset=windows-1250
content-transfer-encoding: quoted-printable

RFC-2388 - 5.2 - The coding multipart/form-data has high overhead and some impact on performance if there are too many fields with low values. But in practice this overload is not significant. If you really want more details, or it is not clear enough, you will need to read this and some of the other Rfcs for a better analysis of gains and losses. Another good font would be this page here of W3.

5


According to that question on Stack Overflow, there are three values you can pass in the enctype:

  • application/x-www-form-urlencoded (pattern)
  • multipart/form-data
  • text/plain

The general rule is: if you are uploading files, use multipart/form-data; otherwise, use application/x-www-form-urlencoded. Never use text/plain.

To answer your question: when you do not attach any file type in your form, I believe it is best to use multipart/form-data. This format uses fewer bytes than the application/x-www-form-urlencoded. Therefore, the server-side processing should also be lower by manipulating a smaller string.

  • Actually, I did the test with a form with two fields in both modes. No multipart/form-data the content-length of the post got much bigger. I believe the only problem then is performance. Thank you.

-4

When you are making a form, you need to specify the file type you want to upload.

By default, it is used:

enctype="multipart/form-data"
  • 2

    But that’s not what’s being asked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.