Javascript 如何使用axios通过http上传图像文件

Javascript 如何使用axios通过http上传图像文件,javascript,axios,Javascript,Axios,我正在使用axios将图像文件上载到服务器,但失败。代码如下: let data = new FormData() data.append('image', image) axios({ type: type, payload: { request: { url: url, method: 'post', timeout: 60000, headers: { 'ACCESS_TOKEN': token, 'Content-Type':

我正在使用axios将图像文件上载到服务器,但失败。代码如下:

let data = new FormData()
data.append('image', image)
axios({
type: type,
payload: {
  request: {
    url: url,
    method: 'post',
    timeout: 60000,
    headers: {
      'ACCESS_TOKEN': token,
      'Content-Type': 'multipart/form-data',
    },
    data: data
  }
})
我收到了400个错误的请求。以下是服务器的响应:

{"timestamp":1480851939951,"status":400,"error":"Bad Request","exception":"org.springframework.web.multipart.support.MissingServletRequestPartException","message":"Required request part 'image' is not present.","path":"/upload/image"}
我使用postman测试了服务器api,它运行良好。我的代码怎么了

EDIT1 图像对象是从中获取的。下面是获取图像对象的代码

    var fr = new FileReader();
    fr.onload = function () {
      let image = fr.result()  //image is got here

    }
    fr.readAsDataURL(file);

你能说得更具体些吗?你所说的附加是什么意思?文件对象来自哪里?文件只是一个url字符串。你找到解决方法了吗?