我尝试使用 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>
控制器:
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[]
但它也不起作用。
我还看到这里也有同样的问题(here https://stackoverflow.com/questions/7635145/multiple-file-upload-in-playframework),使用这个作为答案:
List<Upload> files = (List<Upload>) request.args.get("__UPLOADS");
但它在 Play! v1.2.4 中不起作用。
我正在使用 Play v1.2.4。
真的非常感谢您的帮助!
嗯,我已经开了一个ticket https://play.lighthouseapp.com/projects/57987/tickets/1391-multiple-file-uploads-only-show-the-first-file#ticket-1391-1正在上映!框架,因为它似乎是个问题,而且显然,我不是唯一一个有这种行为的人。
我用新的 1.2.5 进行了测试,问题得到了解决,至少我在问题上给出的解决方案是这样的:
public static void upload() {
File[] images = params.get("image", File[].class);
for (File f : images) {
Logger.info (f.getName());
}
}
注意:我使用的是 Java 7!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)