Reputation: 2632
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 TemporaryFile
to java.nio ByteBuffer
?
Upvotes: 1
Views: 1274
Reputation: 170733
val bytes = Files.readAllBytes(tempFile.file.toPath)
gives you an Array[Byte]
. If you really need a ByteBuffer
, use ByteBuffer.wrap
.
Upvotes: 3