HTTP multipart/form-data multiple files in one <input>

前端 未结 1 1213
谎友^
谎友^ 2021-02-06 17:07

The background:

According to W3c, multiple files selected in a field, should be send by \"multipart/mixed\" type with separate boundary stri

相关标签:
1条回答
  • 2021-02-06 17:29

    I have confirmed what you found. I tested Firefox and Chromium, and this is what I get:

    Content-Type: multipart/form-data; boundary=---------------------------148152952621447
    
    -----------------------------148152952621447
    Content-Disposition: form-data; name="files"; filename="fileOne.txt"
    Content-Type: text/plain
    
    this is fileOne.txt
    -----------------------------148152952621447
    Content-Disposition: form-data; name="files"; filename="fileTwo.txt"
    Content-Type: text/plain
    
    this is fileTwo.txt
    -----------------------------148152952621447--
    

    After an investigation, I found that the W3c information you provided is based on RFC2388, which is already made obsolete by RFC7578.

    According to RFC7578 Section 4.3 (with my emphasis):

    [RFC2388] suggested that multiple files for a single form field be transmitted using a nested "multipart/mixed" part. This usage is deprecated.

    To match widely deployed implementations, multiple files MUST be sent by supplying each file in a separate part but all with the same "name" parameter.

    So, your question:

    How I should process the POST data?

    My recommendation is ignore that W3c info and follow RFC7578.

    Are there browsers that will send multiple files as a "multipart/mixed" or handling such case is not needed and I should simplify my code?

    Very old browsers may use "multipart/mixed" but the usage is deprecated anyway, so no need to handle such case.

    My recommendation: you should definitely simplify your code.

    0 讨论(0)
提交回复
热议问题