I am trying to implement client side encryption in the jQuery File Upload Plugin. I have tried to follow some information I found along the lines of...
- iterate over the files array,
- replace each item with a Blob representing the encrypted file
- after the encryption is done, invoke the callback
But am struggling I currently have...
var encryptFiles = function (files, callback) {
var reader = new FileReader();
var file = files[0];
var blob = file.slice(0, file.size);
reader.readAsBinaryString(blob);
reader.onload = fileonload;
function fileonload(event) {
var result = event.target.result;
var encrypted = CryptoJS.AES.encrypt(result, "key");
file.
callback();
}
// iterate over the files array,
// replace each item with a Blob representing the encrypted file
// after the encryption is done, invoke the callback
}
$('#fileupload').fileupload({
add: function (e, data) {
encryptFiles(data.files, function () {
data.submit();
});
}
});
This code successfully reads the file to a blob, then encrypts it but I am unsure how to go about replacing the item with the Blob. Can anyone give me some help.