2

I've made a resource with Jersey, that can handle file uploads in @FormDataParam-annotated parameters (the resource is configured to receive query and header parameters too).

Testing with Swagger-UI, as long as I send in a file along with other parameters, everything works fine.
But if I omit the files, and just fill in other parameters, my Java method doesn't receive the request (I verified this with the debugger), which instead ends early with a 400 Bad Request error.

Class declaration:

@Path("/v1/users")
@Produces("application/json")
@Api("UploadDocumento")

public class UploadDocumentResourcesApiV10 extends CommonResourcesApi {

Method declaration:

@Consumes({MediaType.MULTIPART_FORM_DATA})
@POST @Path("{userRef}/documents")
public Response uploadDocuments(
        @HeaderParam("X-Api-Token") String apiToken,
        @PathParam("userRef") String contactId,  
        @QueryParam("desc") String uploadDescription,
        @QueryParam("file1Desc") String file1Description, 
        @FormDataParam("file1") InputStream file1, @FormDataParam("file1") FormDataContentDisposition file1Meta,
        @QueryParam("file2Desc") String file2Description,
        @FormDataParam("file2") InputStream file2, @FormDataParam("file2") FormDataContentDisposition file2Meta) {

I've checked the browser request headers, in particular the Content-Type one, and in both cases they're the same.

Even a test with cUrl gives the same error.

What could be wrong?

watery
  • 5,026
  • 9
  • 52
  • 92
  • did you find a solution? currently having this issue myself and researching an answer. – kyle Jul 18 '17 at 20:24
  • 1
    @kyle Nope, but later on I found that you can write equivalents to servlet filters, check [filters and interceptors](https://jersey.github.io/documentation/latest/filters-and-interceptors.html) – watery Jul 18 '17 at 22:24
  • very nice! Thanks for the response. – kyle Jul 18 '17 at 22:40
  • I'm having this same issue. I wonder why there isn't much out there about this issue. Why can't I get it to accept any FormDataParams? – Brian S Apr 20 '18 at 17:05

0 Answers0