Null pointer exception when trying to upload multiple files

47 views
Skip to first unread message

Kastriot Mustafi

unread,
Dec 17, 2011, 9:08:53 AM12/17/11
to play-framework
Hi all,

I'm trying to upload multiple files.

My template:
#{form @Application.upload(), enctype:'multipart/form-data'}
<input type="file" name="files"><br/>
<input type="file" name="files"><br/>
<input type="file" name="files"><br/>
<input type="submit" value="Upload" />
#{/form}

My controller method:
public static void upload( File[] files ) {

for ( int i=0; i<files.length; i++ ) {
File file = files[i];
if (null == file) continue;

System.out.println( "Absoluter Pfad: " + file.getAbsoluteFile() );
}
String text = params.get( "textfield" );
System.out.println("text: "+ text);
}

It works fine when there are three files to upload.

The problem is that i get a nullpointer when any field is left empty
and i send the form.

Any ideas?

Reply all
Reply to author
Forward
0 new messages