上传报错:
const uploadFilesToServer = (uploadApiUrl, fileName, files) => {
let formData = new FormData()
formData.append(fileName, files)
// console.log(fileName, files, formData.get('upFile'))
//添加请求头
// const headers = {
// 'Content-Type': 'multipart/form-data',
// // 'Content-Type': 'Access-Control-Allow-Origin',
// }
let token = JSON.parse(sessionStorage.getItem('token'))
// const headers = {
// Authorization: token.token,
// }
//配置头
const request = axios.create({
// headers: headers,
Authorization: token.token,
withCredentials: true, // 跨域
})
console.log(uploadApiUrl, fileName, files, formData.get('file'))
//开始上传
return (
request
.post(uploadApiUrl, formData, {
// 'Content-Type': 'multipart/form-data',
})
.then((response) => {
console.log(response)
// return Promise.resolve(response.data)
})
)
}
OPTIONS
请求接口,需确认服务器可以正常响应此请求,并返回正确的响应体withCredentials
只负责传递 cookie 信息,并不解决跨域