Created
January 17, 2013 22:42
-
-
Save jkyamog/4560541 to your computer and use it in GitHub Desktop.
reactivemongo, upload file and create from json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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