当前位置:网站首页>File upload error: current request is not a multipart request
File upload error: current request is not a multipart request
2022-07-26 03:33:00 【The breeze also misses the rain】
Want to upload a file ,spring boot coordination Ajax To carry out . But report a mistake :Current request is not a multipart request
This is a screenshot of the error :

This kind of mistake happened at that time , I was shocked , I thought I found many ways to solve .
There are the following ways , Of course, these did not solve my problem , But part of it works , Just list it first :
1. Add information at the head of the page :
<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />This method Unresolved problem !
2. stay form Form add attribute :enctype
<form method="post" enctype="multipart/form-data">
<input type="file" name="file" />
</form>This method Unresolved problem !
3. Back end :@RequestParam MultipartFile file Change it to @RequestPart MultipartFile file
This method Unresolved problem !
There are individual methods ... Neither.
Here's the solution , Before me ajax Code :
$('#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
}
})
})Correct code :
$('#upload-ok').click(function () {
var form = document.getElementById("upload-form");
var file = new FormData(form);
$.ajax({
url: "/addFile",
type: "POST",
processData:false,
contentType:false,
// Important part ,data It's the whole form , Don't wrap it in braces ; No custom variable name
data:file,
success: function (date) {
xxxxxx
},
error: function (date) {
xxxxxx
}
})
})That's it , solve !!!
边栏推荐
- QT notes - temporary floating window
- [noip2001 popularization group] packing problem
- What's good for starting a business with 10000 yuan? Is we media OK?
- Tf.constant usage
- Hurry in!!! Write a number guessing game with dozens of lines of code based on the basic knowledge of C language
- Portable power fast charging scheme 30W automatic pressure rise and fall PD fast charging
- Visio:甘特图如何合并单元格?解决方案:覆盖单元格
- Installation and operation of orb-slam2 under ROS
- 9-20v input peak charging current 3A dual lithium switch type charging chip sc7102
- Docker installs redis!!! (including detailed illustration of each step) actual combat
猜你喜欢

C language functions (2)

HCIP第十四天

【创建交互式 Dice Roller 应用】

Illustration leetcode - 5. Longest palindrome substring (difficulty: medium)

Completion report of communication software development and Application

ue4如何进行静态渲染?5个步骤生成静态渲染

How to choose sentinel vs hystrix?

UDP和TCP可以使用同一个端口吗?

QT notes - temporary floating window

离线数据仓库从0到1-阶段二软件安装
随机推荐
2020 AF-RCNN: An anchor-free convolutional neural network for multi-categoriesagricultural pest det
QT笔记——Q_Q 和Q_D 学习
Opencv error: (parameter or structure field)) unrecognized or unsupported array type in functon 'cvgetmat‘
Day 7 hcip notes sorting (OSPF configuration)
js中数组排序的方法有哪些
Hcip day 14
Completion report of communication software development and Application
sersync/lsync实时同步
Alibaba Sentinel - 集群流量控制
[class and object instances in kotlin]
Use eventlog analyzer for log forensics analysis
[tensorflow & pytorch] image data enhancement API
称霸薪酬榜!什么行业大有“钱”途?
How Lora wireless gateway can quickly realize end-to-cloud transmission
Etcdv3 actual combat (III) -prevkv description and related operations
NFT因无意义而美丽
2022-07-21 group 4 polymorphism
PXE高效批量网络装机
B2B2C多商户系统功能丰富,极易二开
Unknown-Aware Object Detection:Learning What You Don’t Know from Videos in the Wild(CVPR 2022)