我与您分享了我的代码的一部分,用于对文件进行加密。当我尝试在本地硬盘驱动器上保存加密文件时,此代码工作正常,但当我尝试使用JavaScript Saver API在云上保存加密文件时,我只是以数据URI的形式获取数据。你们中谁都知道如何解决这个问题?
// JavaScript代码:
// The HTML5 FileReader object will allow us to read the
// contents of the selected file.
var reader = new FileReader();
if(body.hasClass('encrypt')){
// Encrypt the file!
reader.onload = function(e){
// Use the CryptoJS library and the AES cypher to encrypt the
// contents of the file, held in e.target.result, with the password
var encrypted = CryptoJS.AES.encrypt(e.target.result, password);
// The download attribute will cause the contents of the href
// attribute to be downloaded when clicked. The download attribute
// also holds the name of the file that is offered for download.
a.attr('href', 'data:application/octet-stream,' + encrypted);
a.attr('download', file.name + '.encrypted');
step(4);
};
// This will encode the contents of the file into a data-uri.
// It will trigger the onload handler above, with the result
reader.readAsDataURL(file);
}
// HTML代码
<div class="content">
<h1>Your file is ready!</h1>
<a class="button download green">Download on Computer</a>
<a class="button download dropbox-saver green">Cloud</a>
</div>
</div>
提前感谢所有助手和努力。