Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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
  }
//...
}
like image 376
Monish Sen Avatar asked Jan 12 '17 07:01

Monish Sen


1 Answers

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.

Setting in manually to 'multipart/form-data', for example, will fail to add the already mentioned boundary.

like image 68
edo.n Avatar answered Oct 17 '22 06:10

edo.n