使用PlayFramework的多个上传文件 [英] Multiple upload file with PlayFramework

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

问题描述

我试图用Play Framework一次上传多个文件,但是我总是得到每个上传的第一张图片。这里有一个具体的例子:

HTML:

 < form method =postaction =/ uploadenctype =multipart / form-data> 
< input type =filename =image/>
< input type =filename =image/>
< input type =filename =image/>
< input type =filename =image/>

< input type =submitname =submitvalue =Send images/>
< / form>

控制器:

  public static void upload(){
File [] images = params.get(image,File []。class);
(文件f:图像){
Logger.info(f.getName());


code
$ b如果我上传image1.jpg,image2.jpg, image3.jpg& image4.jpg,控制台上的 Logger.info 会显示:

  image1.jpg 
image1.jpg
image1.jpg
image1.jpg

其他图片将不会被使用。



我尝试使用 List< File> File [] 但是也不行。

我也看到这里有同样的问题所以(这里),这使用这个答案:

 列表<上传> files =(List< Upload>)request.args.get(__ UPLOADS); 

但在Play!v1.2.4中不起作用。



我正在使用Play v1.2.4。



非常感谢您的帮助!
<我已经打开了一个

在Play上只显示第一个文件#ticket-1391-1rel =nofollow> ticket !框架,因为它似乎是问题,显然,我不是唯一一个有这种行为。



我测试了新的1.2.5,并且问题是固定的,至少用我给出的解决方案:

  public static void upload(){
File [] images = params.get(image,File []。class);
(文件f:图像){
Logger.info(f.getName());


$ / code $ / $ p

注意我正在使用Java 7! p>

I'm trying to upload multiple files at once with Play Framework, but I always get the first image for each uploaded. Here's a concrete case :

The 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>

The controller :

public static void upload() {
    File[] images = params.get("image", File[].class);
    for (File f : images) {
        Logger.info (f.getName());
    }
}

If I upload image1.jpg, image2.jpg, image3.jpg & image4.jpg, the Logger.info on the console will display :

image1.jpg
image1.jpg
image1.jpg
image1.jpg

The other images won't be used.

I tried with List<File> instead of File[] but it doesn't work neither.

I also saw there is kind the same question here on SO (here), that use this as an answer :

List<Upload> files = (List<Upload>) request.args.get("__UPLOADS");

But it doesn't work in the v1.2.4 of Play!.

I'm using Play v1.2.4.

Thank you really much for your help!

解决方案

Well, I have opened a ticket at Play! Framework because it seems to be problem, and apparently, I'm not the only one to have this behavior.

I tested with the new 1.2.5, and the problem is fixed, at least with the solution I gave on the question :

public static void upload() {
    File[] images = params.get("image", File[].class);
    for (File f : images) {
        Logger.info (f.getName());
    }
}

Note: I'm using Java 7!

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

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