Play2-ReactiveMongo GridFS

185 views
Skip to first unread message

ronny...@gmail.com

unread,
Jan 18, 2017, 8:14:07 AM1/18/17
to ReactiveMongo - http://reactivemongo.org
Hello,

I'm trying to upload and read files with GridFS and have run into problems since upgrading to reactivemongo 0.12.1 (using play 2.5.10)

When I try to do an upload (see my code below), the server stops with the error

Uncaught error from thread [application-akka.actor.default-dispatcher-2] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[application]
java.lang.NoClassDefFoundError: play/api/libs/concurrent/StateMachine
...
at play.api.libs.streams.Streams$.iterateeToAccumulator(Streams.scala:204)
at play.modules.reactivemongo.MongoController$$anonfun$gridFSBodyParser$2.apply(MongoController.scala:182)
at play.modules.reactivemongo.MongoController$$anonfun$gridFSBodyParser$2.apply(MongoController.scala:179)
at play.core.parsers.Multipart$$anonfun$multipartParser$1$$anonfun$7.apply(Multipart.scala:79)...
I tried to code as shown on http://reactivemongo.org/releases/0.12/documentation/tutorial/play.html ("Helpers for GridFS"), here is the GridFS related part of my class:

class Attachments @Inject() (
  val messagesApi: MessagesApi,
  val reactiveMongoApi: ReactiveMongoApi,
  implicit val materializer: akka.stream.Materializer,
  ...
) extends Controller with MongoController with ReactiveMongoComponents with SubmitActionBuilders { 

  import MongoController.readFileReads
  val fsParser = gridFSBodyParser(reactiveMongoApi.gridFS) // gridFSBodyParser is deprecated
  def addFile() = Action.async(fsParser) { implicit request =>
    Logger.info("uploading")
    val futureFile: Future[ReadFile[JSONSerializationPack.type, JsValue]] = request.body.files.head.ref
    ...
  } 
}


The logging message "uploading" never is logged, the server crashes before that.


I also tried the code from the crud example https://github.com/ReactiveMongo/reactivemongo-demo-app/blob/master/app/controllers/Articles.scala: 


 class Attachments @Inject() (
  val messagesApi: MessagesApi,
  val reactiveMongoApi: ReactiveMongoApi,
  implicit val materializer: akka.stream.Materializer,
  ...
) extends Controller with MongoController with ReactiveMongoComponents with SubmitActionBuilders { 
private val gridFS = for {
  fs <- reactiveMongoApi.database.map(db =>
    GridFS[JSONSerializationPack.type](db))
  _ <- fs.ensureIndex().map { index =>
  // let's build an index on our gridfs chunks collection if none
  //Logger.info(s"Checked index, result is $index")
  }
} yield fs
def addFile2() = {
  def fs = Await.result(gridFS, Duration("5s"))
  Action.async(gridFSBodyParser(fs)) { request =>  // gridFSBodyParser is deprecated
    val futureFile = request.body.files.head.ref  
The same error happens.

What am I missing? Additionally, can I get rid of using deprecated versions of gridFSBodyparser()?

Thanks a lot!

Cédric Chantepie

unread,
Jan 18, 2017, 9:28:02 AM1/18/17
to ReactiveMongo - http://reactivemongo.org
I guess you are using ReactiveMongo driver with Play, not using the Play-ReactiveMongo module ?

Yaron David

unread,
Feb 9, 2017, 8:53:40 AM2/9/17
to ReactiveMongo - http://reactivemongo.org
This is happening to us too.

We are using Play 2.5.9 (tried with version up to 2.5.12)
With reactivemongo-play 0.12.1

Leo Haskin

unread,
May 18, 2017, 3:43:54 PM5/18/17
to ReactiveMongo - http://reactivemongo.org
Reply all
Reply to author
Forward
0 new messages