Skip to content

Instantly share code, notes, and snippets.

@jkyamog
Created January 17, 2013 22:42
Show Gist options
  • Save jkyamog/4560541 to your computer and use it in GitHub Desktop.
Save jkyamog/4560541 to your computer and use it in GitHub Desktop.
reactivemongo, upload file and create from json
def uploadFile = Action(gridFSBodyParser(gridFS)) { request =>
val upload = request.body.files.head.ref
Async {
upload.map {
case file => {
Ok("File uploaded" + file.id)
}
}.recover {
case _ => BadRequest
}
}
}
def createDocument = Action(parse.json) { request =>
request.body.validate[ResearchDocument].map {
case doc => {
Async {
collection.insert[JsValue](request.body).map{lastError =>
if (lastError.ok) {
Ok("need to get what was inserted")
} else
InternalServerError("Mongo LastErorr:%s".format(lastError))
}
}
}
}.recoverTotal {
case e => BadRequest("not valid document " + JsError.toFlatJson(e))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment