我正在尝试使用restangular进行文件上传请求,我想在restangular中实现与下面相同的功能.但是,我不确定如何为此特定请求设置内容类型和transformRequest.如果我理解正确,setDefaultHeader会为所有后续请求设置它.还有其他方法吗?
myApp.service('$fileUpload', ['$http', function ($http) {
this.uploadFileToUrl = function(file, uploadUrl){
var filedata = new FormData();
filedata.append('file', file);
$http.post(uploadUrl, filedata, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function(){
})
.error(function(){
});
}
}]);
Run Code Online (Sandbox Code Playgroud)