formdata上传文件为空
1.项目中请求拦截器进行了加密处理
// http请求拦截器
var loadinginstace
axios.interceptors.request.use(
config => {
config.showLoading = true
if (config.data != {}) { //加密封装
if (typeof config.data == "object") {
config.data = {
"requestData": unit.encrypt(JSON.stringify(config.data))
}
} else {
config.data = {
"requestData": unit.encrypt(config.data)
}
}
}
if (config.Type != undefined) {
config.headers["Content-Type"] = config.Type
} else {
config.data = Qs.stringify(config.data);
}
if (localStorage.user_token) {
config.headers.Authorization = 'Bearer ' + localStorage.user_token
}
if (config.showLoading) {
showFullScreenLoading();
}
return config;
},
error => {
Message.error({
background: true,
duration: 0,
content: '加载超时'
});
Message.destroy()
return Promise.reject(error)
})
当调用上传文件接口 formdata 就会进行加密 文件上传失败
2.需要吧上传文件接口 跳过加密封住
跳过加密
if (config.data != {} && config.url != "/applyLand/uploadFile") //加密封装
axios.interceptors.request.use(
config => {
config.showLoading = true
if (config.data != {} && config.url != "/applyLand/uploadFile") { //加密封装
if (typeof config.data == "object") {
config.data = {
"requestData": unit.encrypt(JSON.stringify(config.data))
}
} else {
config.data = {
"requestData": unit.encrypt(config.data)
}
}
}
if (config.Type != undefined) {
config.headers["Content-Type"] = config.Type
} else {
config.data = Qs.stringify(config.data);
}
if (localStorage.user_token) {
config.headers.Authorization = 'Bearer ' + localStorage.user_token
}
if (config.showLoading) {
showFullScreenLoading();
}
return config;
},
error => {
Message.error({
background: true,
duration: 0,
content: '加载超时'
});
Message.destroy()
return Promise.reject(error)
})
跳过加密 请求就成功发布