Search code examples
htmlformsmultipart

Is there any downside in setting a form to multipart in HTML?


I'm dynamically building forms and at the time I output the form tag I'm not sure if the form will or will not have a file field. Is there any downside to always making these forms multipart? Why aren't we making all forms everywhere multipart?


Solution

  • As far as I know there isn't a downside. Maybe the text/plain can be a little bit lighter on the transaction but I don't think is considerable. But for markup reasons, to keep your code clean I would only use the multipart when you're actually uploading a file.

    EDIT

    I just did the test using a simple form and Fiddler and the results are:

    -text/plain: 1,552 bytes sent
    -mulipart/form-data: 1,644 bytes sent
    

    Text/plain is a very little bit lighter in this case.

    Now if you have a bigger form the results are:

    -text/plain: 1,772 bytes sent
    -mulipart/form-data: 2,837 bytes sent
    

    Apparently the difference will be higher as the size of the form increases.

    I can't say that this is a enough difference if making everything a multipart will make your life easier.