Skip to content

JS Axios 文件上传

Published: at 11:56 AMSuggest Changes

用 Axios 上传文件的几种方式

var formData = new FormData();
var imagefile = document.querySelector('#file');
formData.append("image", imagefile.files[0]);
axios.post('upload_file', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
})
var formData = new FormData();
formData.append("image", imagefile.files[0]);
export function uploadFile(data: any) {
  return axios({
    url: '/upload',
    method: 'post',
    data
  });
}
uploadFile(formData)

Previous Post
JS input 文件上传格式限制
Next Post
CSS: 视频相对容器全宽