Does anyone know how to create the RestEasy client side calls to upload a file using the following two interface signatures? I'm not finding any information at all. I know how to do it using the HttpClient but I'd like to use the client proxy to keep it consistent.
@POST
@Path("/upload")
@Consumes("multipart/form-data")
public void uploadFile(MultipartFormDataInput input);
@POST
@Path("/upload2")
@Consumes("multipart/form-data")
public void uploadFile2(@MultipartForm FileUploadForm form);
Any help would be appreciated, Fredrik
To pass the Json and Multipart in the POST method we need to mention our content type in the consume part. And we need to pass the given parameter as User and Multipart file. Here, make sure we can pass only String + file not POJO + file. Then convert the String to Json using ObjectMapper in Service layer.
RESTEasy is a JBoss / Red Hat project that provides various frameworks to help you build RESTful Web Services and RESTful Java applications. It is an implementation of the Jakarta RESTful Web Services, an Eclipse Foundation specification that provides a Java API for RESTful Web Services over the HTTP protocol.
With RESTEasy 3.0.X a file upload via MultipartFormData could look like this:
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("http://.../upload");
MultipartFormDataOutput mdo = new MultipartFormDataOutput();
mdo.addFormData("file", new FileInputStream(new File("....thermo.wav")),
MediaType.APPLICATION_OCTET_STREAM_TYPE);
GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(mdo) {};
Response r = target.request().post( Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
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