这个问题,搜索到一篇博文
http://uncorkedstudios.com/blog/multipartformdata-file-upload-with-angularjs
可能版本不同,1.4.5版本Content-Type设置为undefined时,取的是默认的ContentType
查看源码,原来可以设置一个函数来返回ContentType,当函数返回值为undefined时,浏览器会自己加上正确的ContentType
this.uploadBinaryFile = function (files, field) {
var defered = $q.defer();
var formData = new FormData();
if (angular.isArray(files)) {
angular.forEach(files, function (file) {
formData.append(field || "file", file);
});
} else {
formData.append(field || "file", files);
}
$http({
url: "/upload",
method: "POST",
data: formData,
transformRequest: angular.identity,
headers: {
"Content-Type": function () {
return undefined;
}
}
}).success(function (result) {
defered.resolve(result);
}).error(function (result, status) {
defered.reject(status);
});
return defered.promise;
};
来源:oschina
链接:https://my.oschina.net/u/988385/blog/630588