如何使用antd上传反应发送多部分/表单数据 [英] How to send multipart/form-data with antd upload react

查看:35
本文介绍了如何使用antd上传反应发送多部分/表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react 和 antd.
我在 antd 中使用的组件是 拖放.
我正在尝试使用 FormData 对象发送多部分/表单数据.
它发送文件(应作为 blob 发送的 .zip 文件),但它不会将其作为 blob 发送,也不会发送任何与其他键和值相关的内容.
这是一个沙盒.

I am using react and antd.
The component I am using from antd is Drag and Drop.
I am trying to send multipart/form-data using FormData object.
It sends the file (.zip file that should be sent as blob) but it does not send it as blob nor anything related to the other keys and values.
Here's a 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

实际请求 Paylod:

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


------WebKitFormBoundaryysdTGvf0cRZVGpQ4

推荐答案

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

I have used customRequest to solve this problem.
You can find an example here: Send multipart/form-data with antd upload #11616

这篇关于如何使用antd上传反应发送多部分/表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆