Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add multiple file upload directive #1033
Adds support for multiple file uploads with the same field name.
// scaladsl def fileUploadAll(fieldName: String): Directive1[immutable.Seq[(FileInfo, Source[ByteString, Any])]] // javadsl def fileUploadAll(fieldName: String, inner: JFunction[JList[JMap.Entry[FileInfo, Source[ByteString, Any]]], Route]): Route
Following review at #1033 (review) there are a few outstanding pieces of work that need to be done before merge
I've updated the implementation to buffer to disk and squashed the commits into one. The changes now include 2 directives, where the first depends on the second.
def fileMultiUpload(fieldName: String): Directive1[immutable.Seq[(FileInfo, Source[ByteString, Any])]] def uploadedFiles(fieldName: String): Directive1[immutable.Seq[(FileInfo, File)]]
I had started to go down the route of a custom GraphStage to buffer to disk, just like Alpakka's akka.stream.alpakka.s3.impl.DiskBuffer but it proved harder to implement and more complex than necessary. I also couldn't figure out a way to guarantee reading from a written-to file. Maybe chunking writes may have helped but I still don't see any guarantees.
Another solution I tried was
The final solution looks too simple to me, but I've tested it with multiple large files and they stream over perfectly fine. I suppose the only downside is that we effectively have to wait for all ByteString sinks to complete before we can begin sourcing again from disk.
referenced this pull request
Jul 10, 2017
This is looking quite good (even it seems to simple, streams should make things simple ;) ).
Apart from the few comments, it also needs documentation before it can be merged.
Thanks for the feedback. I stuck with similar names to the single file uploads, just for consistency, but I'm happy to change them to be more descriptive. I'll also get onto your other points like separating temp file construction etc. too.
Don't worry about the delay - I've been buried under a mountain of work too. I'll try to get this updated within the next week.
Hey @jrudolph, I've made some updates since your last review
I've also taken a couple of further steps
Let me know what you think, and whether you agree with
I've added the
In addition to the change, I've squashed the commits into more reasonable, safe, chunks of work.
Docs added and Johanness's PR also merged, everything looks good