Java-blueimp jquery file upload List<FileItem> is empty?

778 views Asked by At

I used Jquery file upload with backend java. Am getting

if(ServletFileUpload.isMultipartContent(request) is true.

but

List<FileItem> items = uploadHandler.parseRequest(request);

returns empty.I have not accessed request parameters before.

I google it and found change from /* to /*.action in web.xml will solve the problem. But by this change the struts2 project is not running.

1

There are 1 answers

3
Andrea Ligios On BEST ANSWER
  1. That change makes no sense, both values ( */ and /*.action) are wrong, it should be /*.

  2. You should never parse a Multipart Request by yourself, especially when there are tools out there like Apache Commons FileUpload doing it for you, most likely better than you. Quoting BalusC:

    Parsing such a stream requires precise background knowledge of how multipart form data requests are specified and structured. To create a perfect multipart parser you'll have to write a lot of code. But fortunately there's the Apache Commons FileUpload which has proven its robustness with years.

  3. Struts2 already handles that. You only need to understand how the file upload process works in Struts2.

    Try with a single file in an <s:file/> element first, then with multiple files in a <s:file/> , and finally add Blueimp's jQuery-File-Upload to the equation.

    Notice that with external libraries, it might be necessary to make small modifications, like in the case of Dropzone.js (drag and drop uploader).