如何使用 antd upload react 发送 multipart/form-data

How to send multipart/form-data with antd upload react

我正在使用 react 和 antd。
我使用的 antd 组件是 Drag and Drop.
我正在尝试使用 FormData 对象发送 multipart/form-data。
它发送文件(应作为 blob 发送的 .zip 文件)但它不会将其作为 blob 发送,也不会发送与其他键和值相关的任何内容。
这是 Sandbox

预期请求负载:

------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="file"; filename="aFileName.zip"
Content-Type: application/octet-stream

[0,1,2]
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="x2"

y2
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="x3"

true
------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="x4"

2
------WebKitFormBoundaryysdTGvf0cRZVGpQ4

实际请求负载:

------WebKitFormBoundaryysdTGvf0cRZVGpQ4
Content-Disposition: form-data; name="file"; filename="aFileName.zip"
Content-Type: application/zip


------WebKitFormBoundaryysdTGvf0cRZVGpQ4

我已经使用customRequest解决了这个问题。
你可以在这里找到一个例子:Send multipart/form-data with antd upload #11616

如果您只想使用 <Upload> 作为文件输入并且只有 <Form> 为您提交文件,这里是 my solution