help wanted
描述
I am currently porting an akka-http project to Finagle. One feature I liked about akka-http is that it exposes file uploads as a stream. In Finagle, large files may get written to disk. Furthermore, the interface for accessing the content of file uploads is slightly inconvenient, requiring me to use pattern matching several times:
val r = req.multipart.flatMap(
_.files.collectFirst {
case (k, v) if k == "file" => v
}.flatMap(_.headOption))
val file = r.map match {
case d: http.exp.Multipart.OnDiskFileUpload => d.content
case m: http.exp.Multipart.InMemoryFileUpload =>
m.content match {
case Buf.ByteArray.Owned(bytes, _, _) =>
val f = File.createTempFile("upload", ".tmp")
val fw = new FileOutputStream(f)
fw.write(bytes)
fw.close()
f
}
}