在 Scala 中播放临时文件到 blob 字节缓冲区

Play temporary file to blob Byte Buffer in Scala

我使用 multipart from data 从前端获取文件,我可以将文件保存在服务器目录中:

request.body.file("fileUpload").map { file =>
  file.ref.moveTo(new File("filename"), true)
}

如何将此文件作为 blob 保存到数据库中,换句话说,如何将 Play API TemporaryFile 转换为 java.nio ByteBuffer

val bytes = Files.readAllBytes(tempFile.file.toPath)

给你一个Array[Byte]。如果你真的需要 ByteBuffer,请使用 ByteBuffer.wrap