Created
January 31, 2017 02:21
-
-
Save andrewhyeung/69e1d18cc0eb9ec004fec42b5ff7b2f7 to your computer and use it in GitHub Desktop.
upload javascript in controller
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
var handleFileSelect=function(evt) { | |
var file=evt.currentTarget.files[0]; | |
var reader = new FileReader(); | |
reader.onload = function (evt) { | |
$scope.$apply(function($scope){ | |
$scope.myImage=evt.target.result; | |
}); | |
}; | |
reader.readAsDataURL(file); | |
}; | |
$scope.uploadFiles = function (file) { | |
var cropped = Upload.dataUrltoBlob(file); | |
// console.log($scope.user); | |
// console.log(files[0]); | |
cropped.url = $scope.user._id+'.jpg'; | |
// console.log(file); | |
// $scope.Files = files; | |
// console.log($scope.Files); | |
// file = $scope.Files | |
$scope.File = file; | |
// console.log('this is the file',file); | |
S3UploadService.Upload(cropped).then(function (result) { | |
// Mark as success | |
$scope.success = true; | |
}, function (error) { | |
// Mark the error | |
$scope.error = error; | |
}, function (progress) { | |
// Write the progress as a percentage | |
$scope.progress = (progress.loaded / progress.total) * 100 | |
console.log(progress); | |
setTimeout(function(){ | |
location.reload() | |
}, 1200) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment