How to find the size of a file uploaded via Dropwizard REST API
<p>I am using Dropwizard 0.7.0 to build an API for file upload. Ran into trouble validating the uploaded file size limit. I want to check the size before writing the file to disk</p>

<pre><code>@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public Response uploadFile(@Context final HttpServletRequest request, @FormDataParam("file") FormDataBodyPart fileBodyPart) {

    /*
     * Check the request size
     */
    request.getPart("file").getSize();
.........
}
</code></pre>

<p>it throws an error:</p>

<pre><code>java.lang.IllegalStateException: No multipart config for servlet
at org.eclipse.jetty.server.Request.getParts(Request.java:2075) ~[jetty-  server-9.0.7.v20131107.jar:9.0.7.v20131107]
at org.eclipse.jetty.server.Request.getPart(Request.java:2055) ~[jetty-server-9.0.7.v20131107.jar:9.0.7.v20131107]
</code></pre>

<p>EDIT ----------------------</p>

<p>@David</p>

<p>Upgraded to dropwizard 0.8.0 however ran into another error</p>

<pre><code>com.sun.jersey.spi.inject.Errors: The following errors and warnings have been detected with resource and/or provider classes:
org.glassfish.jersey.media.multipart.file.FormDataBodyPart
org.glassfish.jersey.media.multipart.file.FileDataBodyPart
org.glassfish.jersey.media.multipart.FormDataContentDisposition
</code></pre>

<p>Using these dependencies</p>

<pre><code>&lt;dependency&gt;
 &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
 &lt;artifactId&gt;dropwizard-forms&lt;/artifactId&gt;
 &lt;version&gt;${dropwizard.version}&lt;/version&gt;
&lt;/dependency&gt; 
</code></pre>

<p>and</p>

<pre><code>&lt;dependency&gt;
 &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
 &lt;artifactId&gt;jersey-media-multipart&lt;/artifactId&gt;
 &lt;version&gt;2.23.2&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>

<p>added</p>

<pre><code>bootstrap.addBundle(new MultiPartBundle());
</code></pre>

<p>and this too (after first failure)</p>

<pre><code>env.jersey().register(MultiPartFeature.class);
</code></pre>

<p>what am I missing here?</p>