Skip to content

Instantly share code, notes, and snippets.

@grudelsud
Created June 30, 2015 09:25
Show Gist options
  • Save grudelsud/6e4c471e98f7a5cee3d0 to your computer and use it in GitHub Desktop.
Save grudelsud/6e4c471e98f7a5cee3d0 to your computer and use it in GitHub Desktop.
ng-file-upload example
// 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