多文件上传与播放? [英] multi file upload with play?

查看:25
本文介绍了多文件上传与播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过一个请求上传多个文件.我的代码如下所示:

I try to upload multiple files with one request. My code looks like the following:

<form action="/application/overviewsubmit" method="POST" enctype="multipart/form-data">
 <input type="file" name="files">
 <input type="file" name="files">
 <input type="submit" value="Run...">
</form>

和控制器:

public static void overviewSubmit(List<File> files){
 System.out.println(files);
}

如果这两个文件都是由用户设置的,它就可以工作.但是,如果用户只选择其中之一而另一个保持不变,files 始终为空.

If both files are set by the user it works. But if the user chooses only one of them and leaves the other one untouched, files is always null.

推荐答案

我找到了一种骇人听闻的方法.

I've found a hackish way.

您必须导入 play.data.Uploadplay.data.*

public static void overviewsubmit(File fake) {
    List<Upload> files = (List<Upload>) request.args.get("__UPLOADS");
    for(Upload file: files) {
        Logger.info("Size = %d", file.getSize());
    }
}

如果没有 File fake 参数,该方法将无法处理 multipart/form-data 并且你会得到一个空的 request.args 数组.如果有人知道它的播放/标准注释,请告诉我:)

Without the File fake argument the method will not handle multipart/form-data and you'll get an empty request.args array. If anyone knows the play/standard annotation for it, let me know :)

您可以查看其他有用的功能 - http://www.playframework.org/documentation/api/1.2.3/play/data/FileUpload.html

You can check this for other useful functions - http://www.playframework.org/documentation/api/1.2.3/play/data/FileUpload.html

希望它能解决您的问题.

Hope it'll solve your problem.

这篇关于多文件上传与播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆