hi,
As my images are small, I've tried adding "object image extends BinaryField(this)" to my model, using
https://github.com/eltimn/binaryfield-demo as a base. I think my set is working, but my get doesn't seem to return the data.
set:
def uploadImage(req: Req): Box[LiftResponse] = {
for (file <- req.uploadedFiles) {
println("Received: " + file.fileName)
EventMeta.findByName("BillsBack").map(_.image.set(file.file))
}
Full(OkResponse())
}
After uploading a file - I can read it in the mongo CLI
db.events.find()[0].image
BinData(0,"AA==") <= not sure if that is the trunced binary data of the file I uploaded
I'm doing the get as
def getImage(req: Req): Box[LiftResponse] = {
val event = EventMeta.findByName("BillsBack")
// val data: Array[Byte] = event map (_.
image.is) getOrElse (Array.empty)
val data: Array[Byte] = event match {
case daBinary: Array[Byte] => daBinary
case _ => Array.empty
}
case _ => Array.empty
}
Full(InMemoryResponse(data, Nil, Nil, 200))
}
When I debug the get , it does break on the "daBinary"; however it is an array with a value of "[0] = 0"
Cheers