wiradikusuma
wiradikusuma

Reputation: 1919

Grails, getting InputStream from Controller (or even Servlet)

I'm trying to get inputStream from request, but it's always empty. Any idea how to get the contents of it? I'm trying to make a DataInputStream from it.

Upvotes: 1

Views: 2549

Answers (2)

kuceram
kuceram

Reputation: 3885

For me it works when I request the controller method with "application/octet-stream" MIME and send some data within the request. Than in the controller I can simply do:

import org.apache.commons.io.IOUtils

def test() {
   byte[] requestData = IOUtils.toByteArray(request.getInputStream())
}

That's it :-)

Upvotes: 2

leebutts
leebutts

Reputation: 4882

Are you uploading multipart requests? The request may have already been processed into a Spring MultipartRequest by Grails in which case you can use getFile() to get the upload contents.

If not, then request.inputStream should work fine.

cheers

Lee

Upvotes: 2

Related Questions