I have a multipart form which is supposed to upload a file as well as some parameters. It looks like this:
<form id="upload" action="http://localhost:9998/test" method="post" enctype="multipart/form-data">
<input name="inputfile" type="file" size="50" accept="application/octet-stream">
<input name="someparameter" type="text" size="10">
<input type="submit" value="Go!">
</form>
The web service looks like this:
@Path("/test")
public class ServiceInterface {
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void execute(@FormParam(value="someparameter") String param) {
System.out.println(param);
}
}
When submitting the form, the value for "someparameter" is always reported as null although in the form I entered a value.
My questions are:
I am using Jersey 1.10.
Ok, after googling quite a few hours I found the error in my code.
You have to use the annotation @FormDataParam instead of @FormParam.
The resulting code looks like this:
@Path("/test")
public class ServiceInterface {
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void execute(
@FormDataParam("someparameter") String param
@FormDataParam("inputfile") File inputfile
)
{
System.out.println(param);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With