1

I have a Grails action inside a controller. In this action I use:

def url = "http://www.somedomain.com/image/test.jpg"
def requestFactory = new SimpleClientHttpRequestFactory()
def request = requestFactory.createRequest(uri, method)
...
def response = request.execute()
  if(statusCode == HttpStatus.OK) {
def responseImage = response.body.text
}

This returns a jpg image in my response.body.text object. I have no idea how I can handle this image. How can I convert this image to a byte array?

2
  • Please clarify, the question is unclear. Sending a http request to an image seems a bit odd.. Commented Mar 25, 2013 at 17:17
  • @Marco I updated the question. Do you have any idea what to do? Commented Mar 25, 2013 at 17:54

1 Answer 1

3

ClientHttpResponse.getBody() returns an InputStream, so you could just do response.body.bytes (using the Groovy-JDK InputStream.getBytes() extension) instead of response.body.text

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.