Skip to content

Instantly share code, notes, and snippets.

@AntonisFK
Created May 18, 2016 04:29
Show Gist options
  • Save AntonisFK/36b41ca5021b41b8d573bae23bb88553 to your computer and use it in GitHub Desktop.
Save AntonisFK/36b41ca5021b41b8d573bae23bb88553 to your computer and use it in GitHub Desktop.
ng-upload controller
// this how a controller will look if your uploading multiple files
$scope.uploadFiles = function (files) {
$scope.files = files;
if (files && files.length) {
Upload.upload({
url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
data: {
files: files
}
}).then(function (response) {
$timeout(function () {
$scope.result = response.data;
});
}, function (response) {
if (response.status > 0) {
$scope.errorMsg = response.status + ': ' + response.data;
}
}, function (evt) {
$scope.progress =
Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
console.log($scope.progress)
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment