开发者

Client side (javascript/jQuery) file manipulation before/after upload/download

开发者 https://www.devze.com 2022-12-14 11:42 出处:网络
I\'m just sounding things out about this having looked around for a while and drawn a blank. I\'d like to see if this is even possible as so far I can\'t see a way to do it.

I'm just sounding things out about this having looked around for a while and drawn a blank. I'd like to see if this is even possible as so far I can't see a way to do it.

I want to encrypt a file locally (in the browser using existing libraries) before uploading it. Then I'll need to retrieve it and decrypt it before presenting the file to the user. Specifically, I can't send the file to the server for encryption before storage. Encryption/decryption needs to be performed client side.

Here's a rough flow of what I need to do:

  1. Present user with a find-file widget.
  2. Read file into client side script (i.e. load it locally)
  3. Encrypt it on开发者_开发问答 the client.
  4. Upload encrypted version, flush the client side and store the data.

And, in reverse:

  1. Download the stored, encrypted version of the file.
  2. Decrypt it on the client.
  3. Present the decrypted file back to the user as a download.

I've been looking for some kind of MIME encoding on the client (similar to the way email attachments are MIME encoded before being sent as plain text). I'm particularly interested in a jQuery method, as that's what the rest of my app is using, but plain old javascript would be fine.

Any thoughts or pointers very gratefully received. This is the one I'm mulling over the holidays. So, thanks in advance for any comments.


There is no way to do this using plain Javascript or JQuery due to security restrictions in the browser.

Your best bet is probably taking a open source Flash based upload component like SWFUpload (Flash can much more or the client side) and adding the encryption routines there in ActionScript. Creating a Java applet or an ActiveX control are also valid options.

Depending on what kind of encryption we are talking about, there also may exist ready-made components for the job.


You can't do this with JavaScript. You can, of course, simply use SSL (e.g., via HTTPS). Dead easy, well-tested, all of that. Otherwise, you'll have to use something non-standard like Flash, Java, or ActiveX.


The accepted answer is outdated here. It is possible to do this now using HTML5 File API and something like the CryptoJS library.


I can't speak to other browsers, but I know this should be possible in Firefox by using the file manipulation api to upload/download files from the user to the client-side code (where they may be manipulated), and standard ajax to upload/download files from the client-side code to the server.

0

精彩评论

暂无评论...
验证码 换一张
取 消