删除ngResource angular中的“Content-Type”标题

时间:2016-01-21 14:36:08

标签: angularjs header content-type ngresource

我是棱角分明的新人。在我的应用程序中,我想将文件上传到服务器。根据api,'Content-Type'标题应为null或不发送。我google了,开发人员建议将标头设置为undefined。以下是我的代码

orig_stdout = sys.stdout
sys.stdout=open('OLSYield.txt','w')
print "helloWorld appears in text file"

sys.stdout.close()
sys.stdout=orig_stdout 
print "helloWorld appears in console"

但在开发者视图中,我能够观察到'Content-Type'设置为return $resource(apiHost +'/tessters/:patId?action=:action&format=:format', {patId: '@patId' , action: '@action' ,format: '@format'}, { save: { method: 'POST', transformRequest: angular.identity, headers: {'Content-Type' : undefined,'Authorization': authorizationToken}, } });

enter image description here

并且我无法找到任何方法来删除“内容类型”标题,如果有人知道解决方案,请帮助我

提前致谢

1 个答案:

答案 0 :(得分:2)

请查看以下

      var file = angular.element(document.querySelector('#file')).prop("files")[0]; $scope.files = []; $scope.files.push(file)
      $http({
                method: 'POST',
                url: siteRootURL,
                headers: {'Content-Type': undefined},
                transformRequest: function (data) {formData.append('model', angular.toJson(data.model));                       
                    formData.append('file', data.files[0]);
                    return formData;
                },
                data: {model: $scope.user,files: $scope.files}
            })

另请检查您是否设置了 enctype =' multipart / form-data' 属性。