1

I am looking for a way to upload a file (multipart form data) with the jax-rs client only using the standard apis.

The closest solution I could find was this https://www.adam-bien.com/roller/abien/entry/sending_an_inputstream_to_jax but that does not produce a MultiPart request.

All I have found are specific solutions to a concrete client implementation like RestEASY (https://mkyong.com/webservices/jax-rs/file-upload-example-in-resteasy/) or Jersey (https://howtodoinjava.com/jersey/jersey-file-upload-example/) or skipping JaxRs completely and using HttpClient (FileUpload with JAX-RS), but as the implementation provider will most likely change in the future my best bet would be to stay strictly to the standard API.

Is there something, maybe with JaxRs 2.1 or at least a cross implementation solution? A library providing a MessageBodyWriter or Feature that has just to be registered would be nice too.

dag
  • 1,030
  • 12
  • 23
  • There is no standard JAX-RS API (unless you want to build the raw request yourself, which is doable, but not a simple task). Could you use a third-party library like Apache http client? – Paul Samsotha Dec 15 '20 at 19:26
  • We've used Apache HttpClient before, but in most use cases is so much more verbose and cumbersome to use than what can be achieved in a few simple lines of JaxRs code. That's why we want to migrate to this api wherever possible. Unfortunately I get the feeling, that the JaxRs Client API is rarely adopted and it's a more common to use specific libraries like OkHttp or RestEASY. – dag Dec 16 '20 at 08:14

0 Answers0