[1.2.4] Multiple upload file with PlayFramework

662 views
Skip to first unread message

cx42net

unread,
Jan 17, 2012, 6:50:50 AM1/17/12
to play-framework
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 :

[code]
<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>
[/code]

The controller :

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

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 tried to put the File[] image directly in the method, doesn't
work neither.

I also saw on StackOverflow an alternative :

[code]
List<Upload> files = (List<Upload>) request.args.get("__UPLOADS");
[/code]

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

Thank you really much for your help

Nicolas Leroux - committer

unread,
Feb 21, 2012, 4:19:47 PM2/21/12
to play-fr...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages