我正在尝试使用以下代码在 Play 2.1 中使用 reactivemongo 保存附件:
def upload = Action(parse.multipartFormData) { request =>
request.body.file("carPicture").map { picture =>
val filename = picture.filename
val contentType = picture.contentType
val gridFS = new GridFS(db, "attachments")
val fileToSave = DefaultFileToSave(filename, contentType)
val futureResult: Future[ReadFile[BSONValue]] = gridFS.writeFromInputStream(fileToSave, new FileInputStream(new File(filename)))
Ok(Json.obj("e" -> 0))
}.getOrElse {
Redirect(routes.Application.index).flashing(
"error" -> "Missing file"
)
}
}
我收到以下错误:
找不到参数 readFileReader 的隐式值:reactivemongo.bson.BSONDocumentReader[reactivemongo.api.gridfs.ReadFile[reactivemongo.bson.BSONValue]] [error] val futureResult: Future[ReadFile[BSONValue]] = gridFS.writeFromInputStream(fileToSave,新文件输入流(新文件(文件名)))
我错过了什么?
谢谢,
遗传算法