I am creating a mobile API that accepts some params in headers and a file(optional) in body as multi part. Now when I try to submit with file present, it works just fine, but when the file is not present in the request it says 415 error. below is code request(for submitting I am using Postman in Chrome)
@POST
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@HeaderParam("uid") String userId,
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail) {
// save file to disk
return Response.status(200).entity("Done").build();
}
This is a JAX-RS/Jersey based solution taken from MKYONG tutorial. Let me know if more information is required.