文件上传请求头设置

发布时间 2023-10-23 12:37:48作者: sunny123456

文件上传请求头设置

涉及到文件上传时接口需要配置请求头:headers: { ‘Content-Type’: ‘multipart/form-data’ }
例如:

//导入excel数据
export function importStorage(data) {
    return request({
        url: '/agcloud/zhps/storage/importFile',
        method: 'post',
        headers: { 'Content-Type': 'multipart/form-data' },
        data
    })
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

请求头常用的Content-Type:
什么是ContentType
ContentType指的是请求体的编码类型,常见的类型共有3种:
● 1.application/x-www-form-urlencoded --默认
● 2.multipart/form-data --表单有文件、图片上传时
● 3.application/json

原文链接:https://blog.csdn.net/weixin_44293690/article/details/125178861