上传前更改文件内容 [英] Alter file contents before uploading
本文介绍了上传前更改文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在上传到我们的服务器之前加密文件的内容..我们正在使用fineuploader。
I would like to encrypt the contents of a file before uploading to our server .. we are using fineuploader.
我想做的是:
function onSubmitted(id)
{
var file = uploader.getFile(id);
var reader = new FileReader();
reader.onload = function (e) {
//encrypt here
// but how do I save the file back to fineuploader?
//then continue to submit/upload
};
reader.readAsArrayBuffer(file);
}
有什么方法可以开箱即用,或者我需要诉诸猖獗的hackery :) :)
is there any way of doing this out of the box or will I need to resort to rampant hackery :) :)
推荐答案
如何返回false以拒绝 onSubmit <中的文件/ code>,对其进行加密,然后通过
addBlobs
API方法重新提交加密版本。例如:
How about returning false to reject the file from onSubmit
, encrypt it, then re-submit the encrypted version via the addBlobs
API method. For example:
callbacks: {
onSubmit: function(id) {
if (!fileOrBlob.blob || !fileOrBlob.blob.encrypted) {
var fileOrBlob = uploader.getFile(id),
reader = new FileReader();
reader.onload = function (e) {
//encrypt here
encryptedBlob.encrypted = true;
uploader.addBlobs({name: fileOrBlob.name, blob: encryptedBlob});
};
reader.readAsArrayBuffer(file);
return false;
}
}
}
注意:上面没有经过测试。如果您遇到严重问题,我会在大约9小时内回来查看。
NOTE: The above has not been tested. If you run into serious issues, I'll check back in about 9 hours.
这篇关于上传前更改文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文