Multipart POST request doesn't contain the file uploaded

I want to extend an existing application with a drag and drop file upload feature. The application is built upon Jetty + Wicket. DropzoneJS seems a good way to go. Dropzone provides all front-end work, I just have to wire it up to the back-end.

More easily said than done, as it turns out. First, I created a test application with the Wicket quickstart. I added dropzone to the HomePage:

<!DOCTYPE html> <html>     <head>         <script src=""></script>         <link rel="stylesheet" href="">     </head>     <body>         <form action="/upload" class="dropzone"></form>     </body> </html> 

Dropzone is simply included from its repository. On the server, I mounted a resource reference at /upload:

public class FileUploadResourceReference extends ResourceReference {     public FileUploadResourceReference(String name)     {         super(FileUploadResourceReference.class, name);     }      @Override     public IResource getResource()     {         return new FileUploadResource();     } } 

FileUploadResource will handle processing of uploaded files:

public class FileUploadResource extends AbstractResource {     @Override     protected ResourceResponse newResourceResponse(Attributes attributes)     {         ServletWebRequest request = (ServletWebRequest) attributes.getRequest();          try         {             MultipartServletWebRequest multipartRequest = request          .newMultipartWebRequest(Bytes.megabytes(100), "ignored");             Map<String, List<FileItem>> files = multipartRequest.getFiles();              List<FileItem> fileItems = files.get("file");             for (FileItem fileItem : fileItems)             {                 saveFile(fileItem);             }         }         catch (FileUploadException e)         {             e.printStackTrace();         }          return null;     }      private void saveFile(FileItem fileItem)     {         // not implemented     } } 

Now here's the problem, when uploading files, Dropzone sends a POST-request to my http://localhost:8080/upload. The request is recognized as a multipart request, but the file parameter is absent. A null pointer exception is thrown entering the for-loop:

java.lang.NullPointerException     at com.test.FileUploadResource.newResourceResponse( ~[classes/:?]     at org.apache.wicket.request.resource.AbstractResource.respond( ~[wicket-core-7.4.0.jar:7.4.0]     at org.apache.wicket.request.handler.resource.ResourceRequestHandler.respond( ~[wicket-core-7.4.0.jar:7.4.0]     at org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler.respond( ~[wicket-core-7.4.0.jar:7.4.0] 

I can't figure out what's going on here. According to the Dropzone website, the form declaration should be fine. A bug in Dropzone perhaps? Seems unlikely. Some Jetty configuration parameter that is denying multipart form requests? Seems highly unlikely, at least I've never heard of it.

You can find full source code of my test app on GitHub.


Category: java Time: 2016-07-30 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.112 (s). 12 q(s)