我想使用Play2在elasticsearch上上传一个非常大的CSV文件(数百万行).我写了以下代码,工作正常.
我对第一个块中跳过http响应头的方式不满意.应该有一种方法可以将第一个迭代器链接到跳过http标头并直接切换到完成状态,但我还没有找到.
如果有人可以帮忙
object ReactiveFileUpload extends Controller {
def upload = Action(BodyParser(rh => new CsvIteratee(isFirst = true))) {
request =>
Ok("File Processed")
}
}
case class CsvIteratee(state: Symbol = 'Cont, input: Input[Array[Byte]] = Empty, lastChunk: String = "", isFirst: Boolean = false) extends Iteratee[Array[Byte], Either[Result, String]] {
def fold[B](
done: (Either[Result, String], Input[Array[Byte]]) => Promise[B],
cont: (Input[Array[Byte]] => Iteratee[Array[Byte], Either[Result, String]]) => Promise[B],
error: (String, Input[Array[Byte]]) => Promise[B]
): Promise[B] = state match {
case 'Done =>
done(Right(lastChunk), Input.Empty)
case …Run Code Online (Sandbox Code Playgroud)