简体   繁体   中英

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
  }
//...
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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