2

We are trying to build a stream encrypting flow that takes a video file (+ 1GB) from disk, encrypts it, and uploads it to a server. It seems to be that there is simply no way to do this without loading the full file into memory first.

Looking at Fetch it can support a ReadableStream in the request body. But the browser compatibility isn't good enough: https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#browser_compatibility.

At the moment the upload happens from plain file input, of which we take the stream File.stream(), encrypt it with a custom TransformStream and AES-CBC, but then what? How to get a Readable Stream directly uploaded with Fetch/XHR?

Does anyone have any examples or ideas to do this without loading the file in memory?

Stef
  • 162
  • 10
  • 2
    It uses SSL as well, but we are looking for a solution that ensures that only a user will ever be able to decrypt, so we have to encrypt at client side. – Stef Mar 29 '23 at 14:43
  • If you're holding out for Safari compatibility, you'll probably wait forever. :-( The only other way to send streaming request data is via Web Socket. – Brad Mar 29 '23 at 22:13
  • @Brad, it's both Safari and Firefox that don't support a Readablestream into the request body, so rather substantial I would say. On Web Socket, you are referring to read the stream and send chunks of data as an event over the socket right? Or is there direct support in any way to pass a stream directly? – Stef Mar 30 '23 at 09:24
  • @Stef Yeah, I'm referring to reading the stream and sending chunks... If you have ReadableStream support, you can easily make a Writable to wrap the Web Socket. Last I checked Safari doesn't support this either. Mozilla is working on all of these things, so you'll see it in Firefox eventually... Safari, not so much. – Brad Mar 30 '23 at 19:10

1 Answers1

0

I do not have a direct experience with client-side encryption in the browser but there are already a bunch of existing questions and resources regarding this matter. The following is based on my brief exploration of the topic.

I started here: How should I encrypt large files using clientside JavaScript?.

That leads to more resources, including:

Juraj Martinka
  • 3,991
  • 2
  • 23
  • 25
  • I'm sorry but I'm not really sure what I should do with this info. Thanks for all the info on the encryption itself, but I'm mostly looking to get a ReadableStream of data across without loading it into memory. – Stef Mar 30 '23 at 09:28