小编use*_*226的帖子

在restangular中为单个请求设置标头和http参数

我正在尝试使用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)

post file-upload angularjs restangular

8
推荐指数
3
解决办法
2万
查看次数

标签 统计

angularjs ×1

file-upload ×1

post ×1

restangular ×1