2
我遇到了包含文件上傳和附加輸入字段的Play 2.1.0表單的問題。我用使用其他字段播放文件上傳表單
def uploadTaxonomy() = Action(parse.multipartFormData) {
implicit request =>
request.body.file("xml").map { file =>
val xml = scala.io.Source.fromFile(file.ref.file).mkString
taxonomyForm.bindFromRequest().fold(
formWithErrors => BadRequest(views.html.index(formWithErrors)),
result => {
Taxonomies.create(result._1, xml)
Redirect(routes.Application.index())
}
)
}.getOrElse {
Redirect(routes.Application.index())
}
}
,我的方式是這樣的:
val taxonomyForm = Form(
tuple(
"label" -> text,
"xml" -> text
)
)
的問題是,bindFromRequest()
總是失敗(造成了惡劣請求被返回給客戶端)。
有沒有人知道問題可能在哪裏?
注意:我知道有一個bug in 2.1.0,當在上傳字段中未選擇任何文件時會顯示;但它似乎並不相關。
工程就像一個魅力,謝謝!所以總結一下,解決方案是使用'val taxonomyForm = Form(single(「label」 - > text.verifying(nonEmpty)))''形式。 – Hbf 2013-03-06 10:03:18