Created
June 30, 2015 09:25
-
-
Save grudelsud/6e4c471e98f7a5cee3d0 to your computer and use it in GitHub Desktop.
ng-file-upload example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// upload list of files | |
$scope.onFileSelect = function ($files) { | |
//$files: an array of files selected, each file has name, size, and type. | |
for (var i = 0; i < $files.length; i++) { | |
$scope.uploading = {}; | |
var file = $files[i]; | |
var upload_data = { | |
url: apiBase, | |
method: 'POST', | |
headers: {'X-CSRFToken': CSRF.token() }, | |
file: file | |
}; | |
var progress = function (evt) { | |
$scope.uploading.percent = parseInt(100.0 * evt.loaded / evt.total); | |
}; | |
var success = function (data, status, headers, config) { | |
// file is uploaded successfully | |
loadItems($scope.pagination.page, $scope.pagination.limit); | |
loadMediaTypes(); | |
$scope.uploading = false; | |
}; | |
var error = function(data, status) { | |
Alert.push(Alert.type.danger, 'Your files could not be uploaded at this time, please try again later'); | |
$scope.uploading = false; | |
}; | |
$scope.upload = $upload.upload(upload_data).progress(progress).success(success).error(error); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment