How do you create an endpoint for someone to upload a image using jax-rs without jersey?
this is the code I have written:
@POST
@Path("/uploadImage/")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@QueryParam("uan") String uan, InputStream stream) {
try {
byte[] attachmentBytes = IOUtils.toByteArray(stream);
BufferedImage image = ImageIO.read(new ByteArrayInputStream(attachmentBytes));
return Response.ok().build();
} catch (IOException e) {
System.out.print(e);
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build();
}
}
When I hit the endpoint with or without file I get a 200 OK response.
There are many examples of creating an file upload endpoint using Jersey however i do not want to have to import Jersey just for this one task. This post has an answer using Jersey that does what I want to do: FileUpload with JAX-RS