Exception: The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded

14,462 views
Skip to first unread message

Joel

unread,
Jul 21, 2016, 2:41:41 PM7/21/16
to dropwizard-user
I'm getting the error when trying to post an uploaded file:
The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded

I thought this might be needed, so I added this, with no effect :
bootstrap.addBundle(new MultiPartBundle());

My server call looks like this:

    @POST
    @Path("/upload/{uuid}")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(
            @NotNull @PathParam("uuid") String uuid,
            @NotNull @FormParam("title") String title,

and the curl test call says its sending form-data:
Content-Type: multipart/form-data; boundary=--------------------

I don't understand why it thinks application/x-www-form-urlencoded is involved?

This call works if instead I user QueryParam's rather than FormParams, but that just seems wrong, but I might just have to go that direction if I can't find a solution.

This is on 0.9.3, I'd love to see a working example of file upload w/FormParams. The examples I've found tend not to be current, and seem to match what I have, give or take version changes.

Joel

Joel

unread,
Jul 21, 2016, 10:39:40 PM7/21/16
to dropwizard-user
Turns out I needed to use @FormDataParam, not @FormParam as I was using. :(

Mohammed Chowdhry

unread,
Oct 13, 2016, 3:05:19 PM10/13/16
to dropwizard-user
Very helpful! Thanks!

Casper Aleks

unread,
Feb 13, 2017, 2:22:45 PM2/13/17
to dropwizard-user
I was getting this error:

HTTP Status 500 - java.lang.IllegalStateException: The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded

My method was:
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
@FormDataParam("fajl") InputStream uploadedInputStream,
@FormDataParam("fajl") FormDataContentDisposition fileDetail,
@FormParam("param2") String secondParam) { ...


and after replacing @FormParam with @FormDataParam , everything worked out! :) :) :)
Thank You for posting the solution! I hope my comment will help future Googlers find this more easily.
Reply all
Reply to author
Forward
0 new messages