vue中el-upload上传excel文件报Current request is not a multipart request
时间: 2023-07-08 12:47:53 浏览: 250
这个错误通常是因为上传的请求不是一个 `multipart/form-data` 类型的请求造成的。您可以检查一下您的上传请求,确保它是一个正确的 `multipart` 请求。
如果您使用的是 `el-upload` 这个组件,您可以尝试在组件中添加 `:headers="{ 'Content-Type': 'multipart/form-data' }"` 属性,以确保请求为 `multipart` 类型。例如:
```html
<template>
<div>
<el-upload
action="/your/upload/url"
:headers="{ 'Content-Type': 'multipart/form-data' }"
:on-success="handleSuccess"
:on-error="handleError"
>
<el-button>上传文件</el-button>
</el-upload>
</div>
</template>
<script>
export default {
methods: {
handleSuccess(response) {
console.log(response);
},
handleError(error) {
console.error(error);
},
},
};
</script>
```
如果您不是使用 `el-upload`,那么可以检查一下您的上传请求的 `headers` 是否包含 `Content-Type: multipart/form-data`,如果没有,可以手动添加这个 header。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)