BinaryA BinaryA - 4 months ago 28x
Java Question

Play temporary file to blob Byte Buffer in Scala

I use multipart from data to get file from the front end, I can save the file in a server dirctory:

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

How can instead save this file to the data base as a blob, in other words how can I convert Play API
java.nio ByteBuffer

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

gives you an Array[Byte]. If you really need a ByteBuffer, use ByteBuffer.wrap.