Yrlec
Yrlec

Reputation: 3458

Sending binary data with the Restlet client

I'm trying to send a byte[] (using PUT) with Restlet but I can't find any info on how to do it. My code looks like this:

Request request = new Request(Method.PUT, url);
request.setEntity( WHAT DO I PUT HERE?, MediaType.APPLICATION_OCTET_STREAM);

I had expected to find something along the lines of ByteArrayRepresentation, just like there's a JsonRepresentation and a a StringRepresentation but I couldn't find anything.

Upvotes: 7

Views: 3228

Answers (3)

dfa
dfa

Reputation: 116334

you can try subclassing WritableRepresentation that is especially designed for large representations

Upvotes: 1

Avi Flax
Avi Flax

Reputation: 51819

I believe you want to use an InputRepresentation, like so:

Representation representation = new InputRepresentation(new ByteArrayInputStream(bytes), MediaType.APPLICATION_OCTET_STREAM);
request.setEntity(representation);

Upvotes: 7

Emil H
Emil H

Reputation: 40240

I'm not familiar with restlet, but one way to do it would be to base64 encode the data. Then you could handle it like a regular string.

Upvotes: 1

Related Questions