Streaming HTTP file upload demo for Play 2.1
This small demo shows how large files can be copied from client to a destination without requiring any temporary files, and only requires a minimal memory footprint. For example, FireFox sends 8KB chunks when uploading files, so only a few chunks would be held in memory for each client performing a transfer.
Large uploads, such as movies, should not be completely buffered by the Play app before copying the data to the destination. The Play 2.1 Iteratee examples for doing file upload do not explain how to use small in-memory buffers to stream an upload from the client to a destination.
This demo streams a File upload to a local file; you could easily modify this example to stream elsewhere, such as AWS S3 using the AWS Java SDK.
Just clone the repo and run it with Play on your local machine:
play debug run
You can upload using curl instead of the web browser. Thanks to Andrew Gaydenko for the incantation:
curl -i --no-keepalive -F name=myFile.mp4 -F filedata=@myFile.mp4 http://localhost:9000/upload
Files are uploaded to ~/uploadedFiles.
You'll find inline comments in the code.