I have a JAX RS method that accepts the uploaded file as follows
@POST
@Path("/entity/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) {
// Upload this file to another remote API again on secret server
}
Can someone suggest how can I use InputStream to forward this file to another server that has similar consumer ?
I tried this, which did not work. Something is missing
// Using com.ning.http.client.AsyncHttpClient
final FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap();
map.add("file", fileDetail.getFileName());
map.add("Content-Type","multipart/form-data; boundary=" + boundary);
AsyncHttpClient.BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(postURL);
Response response = requestBuilder.setBody(IOUtils.toByteArray(uploadedInputStream)).setHeaders(map).execute().get();