使用FormData时,Firefox和Safari设置不正确的标头

发布于 2025-01-18 07:01:49 字数 518 浏览 2 评论 0原文

我们有一个文件上传代码部分,我们使用表单数据将文件发送到后端服务。

let formData = new FormData();
formData.append('classFile', values.file || new Blob(), values.file ? values.file.name : '');

我们向后端发出 http post 请求来发送此数据。我们注意到 chrome 上的内容类型已正确设置为 multipart/formdata Chrome 请求标头 而 Firefox/Safari 将它们设置为 application/json。 Firefox 请求标头 我们不会在发布请求上传递任何显式标头。任何有关如何修复它的帮助将不胜感激。

We have a file upload code section where we use Form data to send to the file to the backend service.

let formData = new FormData();
formData.append('classFile', values.file || new Blob(), values.file ? values.file.name : '');

We make a http post request to the backend to send this data. We are noticing that the Content Type is set correctly to multipart/formdata on chrome
Chrome request header
whereas Firefox/Safari sets them to application/json.
Firefox request header
We do not pass any explicit headers on the post request. Any help on how to fix it is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假装不在乎 2025-01-25 07:01:49

您是否尝试过设置显式 Content-Type: multipart/formdata 标头?

Have you tried setting explicit Content-Type: multipart/formdata header ?

飘逸的'云 2025-01-25 07:01:49

我们能够通过将用于HTTP调用的Axios软件包的版本升级到最新版本来解决问题。现在,我们可以在执行HTTP帖子时正确地看到浏览器在Firefox/Safari中自动设置的内容类型和边界。

We were able to resolve the issue by upgrading the version of axios package that was used for the http calls to the latest version. We can now see the content type and boundary automatically set by the browser in both firefox/safari correctly when doing a http post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文