作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 Play Framework 一次上传多个文件,但每次上传时我总是获得第一张图片。这是一个具体的案例:
HTML :
<form method="post" action="/upload" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="file" name="image" />
<input type="file" name="image" />
<input type="file" name="image" />
<input type="submit" name="submit" value="Send images" />
</form>
Controller :
public static void upload() {
File[] images = params.get("image", File[].class);
for (File f : images) {
Logger.info (f.getName());
}
}
如果我上传 image1.jpg、image2.jpg、image3.jpg 和 image4.jpg,Logger.info
在控制台上将显示:
image1.jpg
image1.jpg
image1.jpg
image1.jpg
不会使用其他图像。
我试过 List<File>
而不是 File[]
但它也不起作用。
我在 SO ( here ) 上也看到了同样的问题,使用这个作为答案:
List<Upload> files = (List<Upload>) request.args.get("__UPLOADS");
但它在 Play! v1.2.4 中不起作用。
我正在使用 Play v1.2.4。
非常感谢您的帮助!
最佳答案
嗯,我开了一个ticket正在上映!框架,因为它似乎有问题,显然,我不是唯一有这种行为的人。
我用新的 1.2.5 测试过,问题已经解决,至少我对这个问题的解决方案是这样的:
public static void upload() {
File[] images = params.get("image", File[].class);
for (File f : images) {
Logger.info (f.getName());
}
}
注意:我使用的是 Java 7!
关于file-upload - 使用 PlayFramework 上传多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8880607/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!