在一台电脑上出现提交文件名是中文的时候就报错HTTP Status 400 – Bad RequestRequired MultipartFile parameter 'excelFile&#

探讨了在使用Postman进行文件上传时,遇到中文文件名导致的HTTP 400错误问题。此问题仅在特定电脑环境中出现,更换英文文件名或电脑则正常,初步判断为客户端环境配置所致。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在一台电脑上出现提交文件名是中文的时候就报错HTTP Status 400 – Bad RequestRequired

MultipartFile parameter 'excelFile&#

<!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Required MultipartFile parameter &#39;excelFile&#39; is not present</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><hr class="line" /><h3>Apache Tomcat/8.5.37</h3></body></html>

用的工具是postman
文件名是英文和数字就没问题。

经过排查,换了另外几个电脑试验,另外几个电脑就没有这个问题。

这个属于电脑环境导致。不是服务端的问题。

在Java中实现上传Excel文件并解析数据的功能,通常需要前端使用HTML表单配合JavaScript库如FileReader或第三方库如Fine Uploader或Plupload来进行文件选择。后端则会接收`MultipartFile`作为请求体,使用Apache POI或JExcelAPI等库来读取和处理Excel内容。 以下是一个简单的前端示例(使用Vue.js为例): ```html <!DOCTYPE html> <html lang="en"> <head> <script src="https://cdn.jsdelivr.net/npm/vue@2"></script> </head> <body> <div id="app"> <input type="file" @change="uploadFile($event)"> <p v-if="uploading">正在上传...</p> <p v-else-if="file">{{ fileName }}</p> </div> <script> new Vue({ el: &#39;#app&#39;, data() { return { uploading: false, file: null, fileName: &#39;&#39; } }, methods: { uploadFile(e) { this.uploading = true; const files = e.target.files; if (files.length > 0) { const file = files[0]; // 检查文件是否是Excel if (!file.type.includes(&#39;application/vnd.ms-excel&#39;)) { alert(&#39;请选择Excel文件&#39;); this.uploading = false; return; } // 使用FormData发送到后端 const formData = new FormData(); formData.append(&#39;file&#39;, file); fetch(&#39;/api/upload&#39;, { method: &#39;POST&#39;, body: formData }) .then(response => response.text()) .then(data => { this.fileName = data; this.uploading = false; }) .catch(error => console.error(&#39;Error:&#39;, error)); } } } }); </script> </body> </html> ``` 后端部分(Spring Boot为例),需要处理`MultipartFile`: ```java import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; @PostMapping("/api/upload") public String handleUpload(@RequestParam("file") MultipartFile file) { try { byte[] bytes = file.getBytes(); // 使用Apache POI打开文件并解析姓名和身份证列 FileInputStream fis = new FileInputStream(new ByteArrayInputStream(bytes)); // ... 解析逻辑... fis.close(); // 返回解析结果或文件名,视需求而定 return "文件已上传,解析后的数据..."; } catch (IOException e) { // 处理异常 e.printStackTrace(); return "上传失败"; } } ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值