【发布时间】:2018-03-18 13:59:39
【问题描述】:
我正在将一些元素上传到 S3。我在此链接中使用相同的示例:
myApp.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){
$scope.uploadFile = function(){
var file = $scope.myFile;
console.log('file is ' );
console.dir(file);
var uploadUrl = "/fileUpload";
fileUpload.uploadFileToUrl(file, uploadUrl);
};
此时,它可以工作了,但是现在,我需要捕获上传文件的 url。我怎样才能做到这一点?我是新上传文件:/
myApp.service('fileUpload', ['$http', function ($http) {
this.uploadFileToUrl = function(file, uploadUrl){
var fd = new FormData();
fd.append('file', file);
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function(){
})
.error(function(){
});
}
}]);
提前感谢。
【问题讨论】:
-
不推荐使用
.success和.error方法。如需更多信息,请参阅Why are angular $http success/error methods deprecated? Removed from v1.6?。
标签: javascript angularjs file-upload angularjs-http