I need to invoke a remote REST interface handler and submit it a file in request body. Please note that I don't control the server. I cannot change the request to be multipart, the client has to work in accordance to external specification.
So far I managed to make it work like this (omitting headers etc. for brevity):
byte[] data = readFileCompletely ();
client.target (url).request ().post (Entity.entity (data, "file/mimetype"));
This works, but will fail with huge files that don't fit into memory. And since I have no restriction on filesize, this is a concern.
Question: is it somehow possible to use streams or something similar to avoid reading the whole file into memory?
If possible, I'd prefer to avoid implementation-specific extensions. If not, a solution that works with RESTEasy (on Wildfly) is also acceptable.
application/octet-streamhas a writer that can handleInputStream. Or I thinkStreamingOutputeven works on the client side for all media types, though I haven't tried it, but I imagine it should workStreamingOutput. I think I've used it before on the client side. I can't remember.InputStreaminto the entityEntity.entity(inputStream, "application/octetstream"); AFAIK Jersey can handle it so I guess RestEasy should too.InputStreamwould actually work for any media type also. Have you triedInputStream?