【发布时间】:2014-02-13 01:11:13
【问题描述】:
我正在尝试使用 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(){
});
}
}]);
【问题讨论】:
标签: angularjs post file-upload restangular