Alter file contents before uploading

此生再无相见时 提交于 2019-12-11 05:05:06

问题


I would like to encrypt the contents of a file before uploading to our server .. we are using fineuploader.

What I would like to do is:

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);
}

is there any way of doing this out of the box or will I need to resort to rampant hackery :) :)


回答1:


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;
        }
    }
} 

NOTE: The above has not been tested. If you run into serious issues, I'll check back in about 9 hours.



来源:https://stackoverflow.com/questions/24400415/alter-file-contents-before-uploading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!