Skip to content

Instantly share code, notes, and snippets.

@dpogorzelski
Last active December 25, 2015 14:29
Show Gist options
  • Save dpogorzelski/6991037 to your computer and use it in GitHub Desktop.
Save dpogorzelski/6991037 to your computer and use it in GitHub Desktop.
Client-side File Encryption: Frontend
$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