BinaryA BinaryA - 2 years ago 141
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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download