无法发送图像上传并通过axios使用令牌承载身份验证

时间:2019-01-29 22:28:07

标签: authentication vue.js file-upload http-headers axios

let url = this.globalAPIBaseUrl + 'program/' + this.tmsID + '/updateposters/?posterType=' + imageType;
let j = [{
  posterType: imageType,
  url: imageUrl
}];
axios.patch(url, {
  headers: {
    Authorization: 'Bearer ' + localStorage.getItem('accessToken')
  }
}, j, {
  onUploadProgress: progressEvent => {
    this.basic.status = 'Uploaded: ' + progressEvent.loaded + 'b of ' + progressEvent.total + 'b'
  }
}).then(response => (this.handleUploadComplete(response)));

在我放入“标头”之前,它工作正常,当我使用相同的auth标头,但在其他地方没有“ j”数据变量时,它也能正常工作。

任何建议,我对axios都很陌生。 (这是在vue2.js中)

1 个答案:

答案 0 :(得分:1)

public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // create a new view TextView v = (TextView) LayoutInflater.from(parent.getContext()) .inflate(R.layout.my_text_view, parent, false); ... MyViewHolder vh = new MyViewHolder(v); return vh; } 应该是第二个参数,第三个参数是data对象,您可以在其中设置configheaders回调

onUploadProgress