FileUploadException: the request was rejected because no multipart boundary was found
文章目录
- Intro
- 错误原因 & 解决
- 正确的前端请求方式 MDN
Intro
前端使用 form 提交文件到后端。
使用 jquery/axios/fetch 或其他HTTP客户端程序发送HTTP请求,但是后端(Spring框架)报错如下:
Request processing failed;
nested exception is org.springframework.web.multipartException: Failed to parse multipart servlet request;
nested exception is java.io.IOException:
org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
错误原因 & 解决
我是因为设置了 "Content-Type": "multipart/form-data"
这样的头,才会失败。
这个请求头的格式样例(见https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type):
POST /foo HTTP/1.1
Content-Type: multipart/form-data; boundary=---------------------------974767299852498929531610575
...
其中 multipart/form-data
表示请求内容的数据类型,而后的 boundary和值表示发送数据的边界(用于确定文件何时结束 EOF)。
那我加上 boundary 参数?
可是 boundary 的值是由上传文件的大小影响的,我怎么去确定啊?
答案是不用确定。
(程序员)不要发送 Content-Type
这个请求头。
ref: https://stackoverflow.com/questions/35192841/how-do-i-post-with-multipart-form-data-using-fetch
make sure not to set the Content-Type header. The browser will set it for you, including the boundary parameter.
一定不要在发送请求的时候自己用javascript去设置 Content-Type 头!
浏览器会替你自动设置这个请求头的值(包括 bounday 参数)!
正确的前端请求方式 MDN
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#uploading_a_file
const formData = new FormData();
const fileField = document.querySelector('input[type="file"]');formData.append('username', 'abc123');
formData.append('avatar', fileField.files[0]);fetch('https://example.com/profile/avatar', {method: 'PUT',
// headers: {// "Content-Type": "multipart/form-data" // 我们手动加这个header会导致错误,让浏览器自己去设置这个header即可!
// },body: formData
}).then((response) => response.json()).then((result) => {console.log('Success:', result);}).catch((error) => {console.error('Error:', error);});
FileUploadException: the request was rejected because no multipart boundary was found相关推荐
- 使用postman模拟上传文件到springMVC的坑:the request was rejected because no multipart boundary was found...
参考该文解决问题:http://blog.csdn.net/sanjay_f/article/details/47407063 报错 threw exception [Request processi ...
- the request was rejected because no multipart boundary was found
前端完整报错如下: Could not parse multipart servlet request; nested exception is java.io.IOException: org.ap ...
- 上传文件遇到the request was rejected because no multipart boundary was found
postman 这样测试是ok的, 前端的上传接口是这么写的 return axios({url: '/upload',method: 'post',headers: {'Content-Type': ...
- feign接口调用服务上传图片 报错 the request was rejected because no multipart boundary was found
在用postman 请求这个调用接口的时候,报了the request was rejected because no multipart boundary was found 1.首先检查是否导入了 ...
- org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no mult
例如这个时候我的controller里是以JSON格式接收的,然后就报错了 请求的content-type问题,把content-type改成json就行了 如下: 问题解决
- springboot接收图片报错 request is not a multipart request 和 multipart boundary was found
后台接收图片报错 request is not a multipart request 和 multipart boundary was found request is not a multipar ...
- SpringBoot整合升级Spring Security 报错 【The request was rejected because the URL was not normalized】...
前言 最近LZ给项目框架升级, 从Spring1.x升级到Spring2.x, 在这里就不多赘述两个版本之间的区别以及升级的原因. 关于升级过程中踩的坑,在其他博文中会做比较详细的记录,以便给读者参考 ...
- The request was rejected by the HTTP filter
ISA 2004 console > Configuration > Add-Ins > Web Filters tab > properties of compression ...
- SpringBoot【The request was rejected because the URL was not normalized】
SpringBoot整合ng-alain时报错如下: org.springframework.security.web.firewall.RequestRejectedException: The r ...
最新文章
- 034 Android NavigationView和DrawerLayout实现抽屉式导航设计(侧边栏效果)
- Excel(16)-好学实用的Index!
- L2-026 小字辈-PAT团体程序设计天梯赛GPLT
- 智能陈桥五笔输入法 for linux,陈桥五笔输入法官方下载
- Fortran: namelist
- 搭建安卓开发环境并测试运行安卓开发环境
- AutoCAD 天正建筑2014安装破解
- 哈佛幸福课-幸福笔记
- 公钥,私钥 和数字证书
- android高仿小米时钟,Android仿小米时钟效果
- PMP之项目采购管理
- 哪些方法可以用来提高微信小程序的应用速度?
- dilated convolution
- 【python 算法接口】使用FastAPI框架快速构建高性能的api服务
- 2017 年前端工具趋势
- EFR32蓝牙串口透传程序流程
- 计算机网络知识点全面总结(一篇全懂)
- 架构设计---技术栈01
- java中的逻辑结构
- 腾讯、新浪、淘宝、搜狐的IP库接口,根据IP显示当地的天气功能
热门文章
- 视频直播流媒体服务器的http-flv是如何直播的?
- 线下沙龙 | 5月11日 ,百度智能云网络技术实践分享强势来袭!
- 【数字IC基础】IC(Integrated Circuit,集成电路)常用缩写
- 【前端基础知识】最基础的render渲染函数知识,一看就会
- 算法相关-互联网计算广告学
- 斯坦福的“计算广告学”
- 【安卓开发】简单记账app功能实现开发-期末大作业个人总结
- 二级c语言常用,二级C语言常用库函数.doc
- py-faster-rcnn 中 shell脚本解读:./experiments/scripts/faster_rcnn_alt_opt.sh
- 【Grasshopper基础13】创建可在画布上自由传递的自定义类型数据(上)—— IGH_Goo接口的重要性及其实现