Skip to content

Instantly share code, notes, and snippets.

@sgodbillon
Created January 21, 2013 23:46
Show Gist options
  • Save sgodbillon/4590661 to your computer and use it in GitHub Desktop.
Save sgodbillon/4590661 to your computer and use it in GitHub Desktop.
Upload a file into GridFS using Play2.1 and ReactiveMongo 0.8
package controllers
import play.api.mvc._
import play.api.Play.current
import play.modules.reactivemongo._
import customcommands._
import reactivemongo.bson._
import reactivemongo.bson.handlers.DefaultBSONHandlers._
import play.api.libs.json._
import reactivemongo.api.gridfs._
object Application extends Controller with MongoController {
def gfs = GridFS(database)
def upload() = Action(gridFSBodyParser(gfs)) { request =>
request.body.files.headOption.map { file =>
Async {
file.ref.map { file =>
Ok
}
}
}.getOrElse(BadRequest)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment