gpt4 book ai didi

scala - Play 文件上传 : warn: Sending an 2xx 'early' response before end of request was received

转载 作者:行者123 更新时间:2023-12-03 12:27:44 31 4
gpt4 key购买 nike

试验“Play Scala 文件上传示例”,我收到以下警告:

[warn] a.a.ActorSystemImpl - Sending an 2xx 'early' response before end of request was received... Note that the connection will be closed after this response. Also, many clients will not read early responses! Consider only issuing this response after the request data has been completely read!

有什么办法可以避免这个警告吗?

完整源代码可在此处获得: https://github.com/playframework/play-scala-fileupload-example/tree/2.6.x

这是文件上传处理请求的详细信息:
  type FilePartHandler[A] = FileInfo => Accumulator[ByteString, FilePart[A]]

/**
* Uses a custom FilePartHandler to return a type of "File" rather than
* using Play's TemporaryFile class. Deletion must happen explicitly on
* completion, rather than TemporaryFile (which uses finalization to
* delete temporary files).
*
* @return
*/
private def handleFilePartAsFile: FilePartHandler[File] = {
case FileInfo(partName, filename, contentType) =>
val path: Path = Files.createTempFile("multipartBody", "tempFile")
val fileSink: Sink[ByteString, Future[IOResult]] = FileIO.toPath(path)
val accumulator: Accumulator[ByteString, IOResult] = Accumulator(fileSink)
accumulator.map {
case IOResult(count, status) =>
logger.info(s"count = $count, status = $status")
FilePart(partName, filename, contentType, path.toFile)
}
}

/**
* A generic operation on the temporary file that deletes the temp file after completion.
*/
private def operateOnTempFile(file: File) = {
val size = Files.size(file.toPath)
logger.info(s"size = ${size}")
Files.deleteIfExists(file.toPath)
size
}

/**
* Uploads a multipart file as a POST request.
*
* @return
*/
def upload = Action(parse.multipartFormData(handleFilePartAsFile)) { implicit request =>
val fileOption = request.body.file("name").map {
case FilePart(key, filename, contentType, file) =>
logger.info(s"key = ${key}, filename = ${filename}, contentType = ${contentType}, file = $file")
val data = operateOnTempFile(file)
data
}

Ok(s"file size = ${fileOption.getOrElse("no file")}")
}

最佳答案

这是我刚刚修复的 Play 中的错误 here .它仅在您发出分块请求时发生。它可以通过使用 Play 的 Netty 服务器后端而不是 Akka HTTP 来解决。

关于scala - Play 文件上传 : warn: Sending an 2xx 'early' response before end of request was received,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45732520/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com