AngularJS $http上传文件(AngularJS file upload/post file)

AngularJS  $http上传文件(AngularJS file upload/post file)

$http({

  method:'POST',
  url: 'url',  encType: 'multipart/form-data',
  headers: {
    'Content-Type': undefined
  },
  data: form
})
.success(() => {

  

})
.error(() => {

  

});

值得注意的是,contentType这里设置成了undefined主要是因为AngularJS本身其实是默认上传的是JSON格式的(application/JSON),如果我们将其设置成undefined,则可以保证在data转成formData之前被识别,而之后其实Angular会帮我们自动识别的。

摘自: AngularJS下$http上传文件(AngularJS file upload/post file)

猜你喜欢

转载自blog.csdn.net/hefeng6500/article/details/79494427