admin管理员组文章数量:1291108
For uploading files from angular to a Spring MVC REST WebService, people seem to be setting Content-Type : undefined header in the AJAX request.
What is the purpose of this type of content-type and is it required by Spring MultiPart?
$http.post(uploadUrl, fd, {
transformRequest : angular.identity,
headers : {
'Content-Type' : undefined
}
//...
}
For uploading files from angular to a Spring MVC REST WebService, people seem to be setting Content-Type : undefined header in the AJAX request.
What is the purpose of this type of content-type and is it required by Spring MultiPart?
$http.post(uploadUrl, fd, {
transformRequest : angular.identity,
headers : {
'Content-Type' : undefined
}
//...
}
Share
Improve this question
edited Dec 18, 2018 at 7:53
Javier C.
8,2675 gold badges46 silver badges57 bronze badges
asked Jan 12, 2017 at 7:46
Monish SenMonish Sen
1,8983 gold badges23 silver badges34 bronze badges
1
- fast-forward to 2022 and Typescript 4x, with strict type checking one cannot set the Content-Type to undefined. Setting any other string value wont work. Therefore the content-type header must be omitted entirely. Angular HttpClient will implicitly set it to multipart – Monish Sen Commented Jul 16, 2022 at 8:27
1 Answer
Reset to default 9It 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.
Setting in manually to 'multipart/form-data', for example, will fail to add the already mentioned boundary.
本文标签: javascriptPurpose of ContentType undefined in AngularJS FileUploadStack Overflow
版权声明:本文标题:javascript - Purpose of Content-Type undefined in AngularJS FileUpload - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741503214a2382168.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论