Handle file uploads in a asyn manner to reduce memory footprint


from what i understand in File Uploads – Phoenix v1.3.0-rc.0. File uploads are saved as a temporary file and cleaned out after request is completed. Is there anyway i can do this in a streaming fashion such that no temporary file is involved? I receive user file uploads in a stream and start working on the stream even before upload is completed.

Why i am thinking of doing this?

  1. What if user uploads a huge file? The temporary file is gonna take up space.
  2. It’s more performant because work already starts before file upload is complete.
  3. If somehow file upload fails before it’s completed. I am happy to throw away work done thus far
  4. Memory consumption is low as its effectively size of stream buffer and not size of file uploaded

You can look into or replace Plug.Parsers, but afaik there‘s nothing out of the box supporting streaming.

There is a very good reason for that also apart from the massive work involved.

Server to client streams include all controlled and clean data on a known protocol with a set resource usage.

Client to server stream includes god knows what they chose to throw at you and eat up your server resources!

You might have streamed up an malware, some adult content some copyrighted content, gigs of padded data and ran your server to the ground.

Megaupload etc back in the day achieved this with special executable clients and still had to set restrictions.

Stream file uploads is just asking to be hacked, dossed or trouble with authorities.