简体   繁体   English

AngularJS FileUpload中未定义Content-Type的目的

[英]Purpose of Content-Type undefined in AngularJS FileUpload

For uploading files from angular to a Spring MVC REST WebService, people seem to be setting Content-Type : undefined header in the AJAX request. 为了将文件从angular上传到Spring MVC REST WebService,人们似乎在AJAX请求中设置了Content-Type:undefined头。

What is the purpose of this type of content-type and is it required by Spring MultiPart? 这种内容类型的目的是什么?Spring MultiPart需要它吗?

$http.post(uploadUrl, fd, {
  transformRequest : angular.identity,
  headers : {
   'Content-Type' : undefined
  }
//...
}

It will reset the default header 'application/json' and let the browser fill in the correct Content-Type for us, along with a correct boundary parameter. 它将重置默认标头'application / json',让浏览器为我们填写正确的Content-Type,以及正确的边界参数。

Setting in manually to 'multipart/form-data', for example, will fail to add the already mentioned boundary. 例如,手动设置为“multipart / form-data”将无法添加已提到的边界。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM