2

What is the most canonical way to write serve files with ReactiveMongo version 0.11.2 on play framework ? In old version I can do it with the following controller function

  def img(id: String) = Action.async {
    val file = gridFS.find(BSONDocument("_id" -> BSONObjectID(id)))
    serve(gridFS, file,dispositionMode = "inline")
  }

Current MongoController GridFS uses Json serializer/deserializer that does not work direct for me. I am trying to write something like this ...

class Admin @Inject() (val reactiveMongoApi: ReactiveMongoApi) extends Controller with MongoController with ReactiveMongoComponents {
...
  def img(id: String) = Action.async {
       val file = reactiveMongoApi.gridFS.find(Json.obj("_id" -> Json.obj( "$oid" -> id) 
       serve(reactiveMongoApi.gridFS, file)
  }

} 

But it does not compiles of course with error on gridFS.find line.

No Json deserializer found for type T. Try to implement an implicit Reads or Format for this type.

If I'll start to write (actually move from ReactiveMongo) all implicits for deserialisation and serialisation to ReadFile it works - but is there exists some more elegant way for this?

cchantep
  • 9,118
  • 3
  • 30
  • 41
Oleg
  • 3,080
  • 3
  • 40
  • 51

0 Answers0