BriteSnow / snow

A Lightweight, Google Guice, Simple, and Powerful Web Application Framework that makes building modern Web Application a breeze! Fully open source, Apache V2 licensed.
http://britesnow.com/snow
29 stars 10 forks source link

Multiple FileItem Support Broken -- NPE #47

Closed zamn closed 9 years ago

zamn commented 9 years ago

When using the following form:

<form action="http://localhost:8080/metrics" method="POST"> <input type="file" name="upload" id="upload" multiple> <input type="submit" value="Submit"> </form>

I try to submit a POST request with two files to my binding:

@WebPost("/metrics")
public void getMetrics(@WebParam("upload")FileItem[] uploadFiles) {
      // user the Apache FileUpload FileItem API           
    System.out.println(uploadFiles);
    System.out.println(uploadFiles.getClass());
    System.out.println(uploadFiles.length); // 2
    System.out.println(uploadFiles[0]); // null
    System.out.println(uploadFiles[1]); // null
} 

And the output files in the array are null.

zamn commented 9 years ago

I was able to resolve this by changing the form to:

<form action="http://localhost:8080/metrics" method="POST" enctype="multipart/form-data">

After taking a look in RequestContext.java, I saw that the file upload was not being identified as multipart. I then took a look at the request itself and it was not sending as multipart, which is why this array only contained the parameters of the multi upload but not the FileItems.