当前位置:网站首页>文件上传报错:Current request is not a multipart request
文件上传报错:Current request is not a multipart request
2022-07-26 03:19:00 【清风亦思雨】
想做一个文件上传,spring boot配合Ajax来进行。却报错:Current request is not a multipart request
这是错误截图:

当时发生这种错误,我是很震惊的,我以为找了很多办法来解决。
有以下办法,当然这些并未解决我的问题,但是部分有用,就先列举出来:
1.在页面头部加入信息:
<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />此方法 未解决 问题!
2.在form表单加入属性:enctype
<form method="post" enctype="multipart/form-data">
<input type="file" name="file" />
</form>此方法 未解决 问题!
3.后端:@RequestParam MultipartFile file 改为 @RequestPart MultipartFile file
此方法 未解决 问题!
还有个别方法。。。都不行
下面是解决方法,我之前的ajax代码:
$('#upload-ok').click(function () {
var form = document.getElementById("upload-form");
var file = new FormData(form);
$.ajax({
url: "/addFile",
type: "POST",
processData:false,
contentType:false,
data:{
"file":file
},
success: function (date) {
xxxxxx
},
error: function (date) {
xxxxxx
}
})
})正确代码:
$('#upload-ok').click(function () {
var form = document.getElementById("upload-form");
var file = new FormData(form);
$.ajax({
url: "/addFile",
type: "POST",
processData:false,
contentType:false,
//重要部分,data的传的是整个表单,不用大括号包裹;不用自定义变量名
data:file,
success: function (date) {
xxxxxx
},
error: function (date) {
xxxxxx
}
})
})就这样,解决!!!
边栏推荐
- Use Anaconda to configure the tensorflow of GPU Version (less than 30 series graphics cards)
- Summary of Huawei virtualization fusioncompute knowledge points
- "Xiao Deng's view" the value brought by Siem to enterprises (II)
- Use VRRP technology to realize gateway equipment redundancy, with detailed configuration experiments
- CMD CPM command summary
- YOLOv3: An Incremental Improvement
- Day 7 hcip notes sorting (OSPF configuration)
- Usage of tf.variable() function in tensorflow
- 图解LeetCode——5. 最长回文子串(难度:中等)
- 记一次SQL优化
猜你喜欢

Use eventlog analyzer for log forensics analysis

Derivation of linear regression principle

DDD落地的那叫一个高级

论文精读-YOLOv1:You Only Look Once:Unified, Real-Time Object Detection

sersync/lsync实时同步

【 Kotlin 中的类和对象实例】

YOLOv3: An Incremental Improvement

使用anaconda配置gpu版本的tensorflow(30系列以下显卡)

MPLS basic experiment configuration

Opencv annotates the image (picture frame + writing)
随机推荐
2022-07-21 study notes of group 4 self-cultivation class (every day)
[noip2001 popularization group] packing problem
Classic interview questions -- three characteristics of OOP language
tensorflow中tf.Variable()函数的用法
Performance comparison of ext4, NTFS, XFS, Btrfs, ZFS, f2fs and ReiserFS
[MySQL project practical optimization] complex trigger case sharing
leetcode-169.多数元素
js中数组排序的方法有哪些
CMD CPM command summary
Canvas - ECG design and how to clean the canvas
c语言指针基本知识要点总结(一)
Canvas - drawing pictures - dynamic drawing production
els 修改光标、修改图标
【尤里复裂人】带你轻松理解——深拷贝和浅拷贝
UE4 how to render statically? 5 steps to generate static rendering
URDF 语法详解
dataframe整理:datetime格式分拆;删除特定行;分组整合。
els 初始化窗口类
Service gateway (zuul)
DDD落地的那叫一个高级