这是如何在 play2 中上传文件的文档:https ://github.com/playframework/Play20/wiki/ScalaFileUpload
但是我还有一个问题:我们不能再使用play1的方式了吗?
在 play1 中,我可以上传文件如下:
routes
--------
post /upload Application.upload
Application.java
----------------
public static void upload(File file) { ... }
该操作upload
将自动获取上传的文件。
但是如何在 play2 中做同样的事情呢?
我试过了:
routes:
--------
POST /upload controllers.Application.upload
Application.scala
-----------------
def upload(file: File) = Action { ...}
但它无法编译,错误信息是:
not enough arguments for method upload: (file: java.io.File)
然后我在路由中添加一个参数:
POST /upload controllers.Application.upload(file: java.io.File)
它仍然报告错误:
No QueryString binder found for type java.io.File. Try to implement an implicit QueryStringBindable for this type.