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

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

问题描述

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

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);
}

如果两个文件均由用户设置,则可以使用.但是,如果用户仅选择其中一个,而又不更改其他两个,则文件始终为空.

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天全站免登陆