Last active
December 25, 2015 14:29
-
-
Save dpogorzelski/6991037 to your computer and use it in GitHub Desktop.
Client-side File Encryption: Frontend
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
$scope.onFile = function(files) { | |
//onFile goes through each file inside the files array, encrypts them and | |
//pushes the blobs to an array | |
for (var i = 0; i < files.length; i++) { | |
Crypt.bury(files[i], $scope.key.value, function(blob) { | |
$scope.$apply(function() { | |
$scope.files.push(blob) | |
}); | |
}); | |
} | |
}; | |
$scope.upload = function() { | |
//when the user clicks upload button each encrypted blob is uploaded through | |
//XHR | |
$scope.files.forEach(function(file) { | |
if (typeof file.uploading === 'undefined') { | |
file.uploading = true; | |
$http({ | |
method: 'POST', | |
url: 'file', | |
headers: { | |
'Content-Type': false | |
}, | |
transformRequest: function() { | |
var formData = new FormData(); | |
formData.append('file', file.blob); | |
return formData; | |
} | |
}).success(function(data) { | |
file.uploading = false; | |
file.id = data; | |
}); | |
} | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment