Skip to content

Instantly share code, notes, and snippets.

@andrewhyeung
Created January 31, 2017 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewhyeung/69e1d18cc0eb9ec004fec42b5ff7b2f7 to your computer and use it in GitHub Desktop.
Save andrewhyeung/69e1d18cc0eb9ec004fec42b5ff7b2f7 to your computer and use it in GitHub Desktop.
upload javascript in controller
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