2013-03-05 67 views
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,当在上传字段中未选择任何文件时会显示;但它似乎并不相关。

回答

1

据我所知,xml不应该是窗体定义的一部分,因为您直接从请求主体获取它。

+0

工程就像一个魅力,谢谢!所以总结一下,解决方案是使用'val taxonomyForm = Form(single(“label” - > text.verifying(nonEmpty)))''形式。 – Hbf 2013-03-06 10:03:18

相关问题