Streaming file upload for on-the-fly encryption
Hi,
I am currently working on a project which requires a file (could be anything from a text file to a full movie etc) to be uploaded to a server. I have been using the Jakarta Commons FileUpload for this but the client has expressed a concern over the file being stored in memory or written to a temporary file unencrypted. The idea is to upload the file as a stream and encrypt the file on-the-fly, this is a mandatory requirement of his.
The encryption is being written by another member of the team who says he will need the filestream as an array of bytes.
Any pointers in the right direction will be much appreciated, I believe this may be possible by writing my own version of FIleUploadFactory and FileUpload but there is no information on the Jakarta site on this topic.
Again, any pointers/suggestions will be great.
Cheers,
Adam
[883 byte] By [
adampilksa] at [2007-10-2 16:17:14]

Not much information?
In the directory where I downloaded Commons FileUpload 1.1 to, there's a "docs" directory. It contains a file named "using.html". Load that into your browser. Click Control-F to search for the word "InputStream". Right below that it says "If you do need to access the uploaded data in memory, you need simply call the get() method to obtain the data as an array of bytes." Now just scroll backwards and make sure you did the simple steps to get to that point. It's almost trivial once you get everything installed in the right place.
Hi,
Thanks for the reply. I had come accross that when first writing the upload servlet using the Commons lib, but it seemed to me (and that certainly doesn't mean its true) that the whole file was being uploaded, stored in memory, and then accessed via the get() method to return it as an array of bytes. Obviously this would not fit the requirements, however, if this is not the case then it would be an ideal solution.
If anyone could shed any light on this it would be a great help.
cheers,
Adam
Umm, good point. Yes, it's in memory. But if you want the uploaded file as an array of bytes then I don't see how you can avoid having it in memory, because that's where the array of bytes is located. I think you have some conflicting requirements there.
Hi,
The idea is that the complete file cannot be in memory at any time, not unencrypted anyway. We will have to recieve the file as a stream and encrypt it as we get it. We can wait till we have recieved a certain number of bytes and then encrypt those, then repeat for the rest of the file.
I have looked everywhere for a way to do it, but customising the FileUpload and FileUploadFactory classes (for which there seems to be no explanation) seems to be the only way.
Does anyone have any experience with this?