axios 上传图片, 图片信息已获取到,但是一上传就为空

这是传入之前的打印

clipboard.png

departmentLogo是有值的..但是
传入接口后,参数变为空

clipboard.png

const waitTime=(url)=>{
    return new Promise((resolve, reject)=>{
        setTimeout(()=>{
            reject({msg:'数据响应超时',waitTime:url})
        },70000)
    })  
}

POST2: (url, params={}) => {
    return new Promise((resolve, reject) => {
        console.log(params)
        axios.post(url, params, {
            headers: {
                'Content-Type': 'multipart/form-data',
            }
        })
        .then(response => {
            const res = response.data;
            resolve(res)
        })
        .catch((error) => {
            Err(error);
            reject(error)
        })
    }) 
}


post2: (url, params) => {
    return new Promise((resolve, reject) => {
        Promise.race([XHR.POST2(url, params), waitTime(url)]).then(res => {
            resolve(res)
        }).catch(res => {
            notification.error({
                message: res.message
            })
            reject(res)
        })
    })
}

请问代码有哪里需要更改的,可以让传入后的值不为空吗

阅读 6.1k
2 个回答

file格式 请用formData格式上传

上传文件的话 data需要是: FormData, File, Blob 三种之一
https://github.com/axios/axio...

  // `data` is the data to be sent as the request body
  // Only applicable for request methods 'PUT', 'POST', and 'PATCH'
  // When no `transformRequest` is set, must be of one of the following types:
  // - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
  // - Browser only: FormData, File, Blob
  // - Node only: Stream, Buffer
  data: {
    firstName: 'Fred'
  },

官方上传文件示例
https://github.com/axios/axio...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题