I would like to use Play2 to implement a server that receives a POST of files, process the files as they are received, and send the results to a GET request from another user while the POST is still transferring files. Is it possible to do this with Play2? I already use Play2 to authenticate users, so I would like to use Play2 to handle authentication of this transaction. I use Java, but if needed, I can use Scala. If so, what should I look into? If not, I guess I need to look into some Java NIO frameworks and implement another server.
Share
I don’t think this is possible in Java, but I’ve managed to put together a simple Scala version. You can still use Java for all other parts of you project.
But be aware that it’s just a crude demo, focussing on the “simultaneous up- and download” part and ignoring everything else. I’m not even sure that this is the right way to do it, but it seems to work.
Basically, what you want to do is to use
Concurrent.broadcastto create a input/output stream pair. The output part (Enumeratee) is streamed to the client. Then, you need a customPartHandlerwhich takes the uploaded data as it arrives, and feeds it into the the input part (Concurrent.Channel).Please not that, in order for this example to work, you have to go to the download page first, then start uploading a file.
sample Application.scala
sample index.scala.html