Using Stream Result with Struts2

19.4k Views Asked by At

I am attempting to use a Stream Result to return an image from a struts2 application. I seem to be having problem with configuring the action. Here is the configuration:

    <result name="success" type="stream">
            <param name="contentType">image/jpeg</param>
            <param name="inputName">inputStream</param>
            <param name="contentDisposition">filename="${filename}"</param>
            <param name="bufferSize">1024</param>
    </result>

The problem seem to be the inputName parameter which according to the docs is:

the name of the InputStream property from the chained action (default = inputStream).

I am not sure what name I should put there. The error I get is:

Can not find a java.io.InputStream with the name [inputStream] in the invocation stack.

Has anyone used this before? Any advice?

Thanks.

3

There are 3 best solutions below

0
Vincent Ramdhanie On BEST ANSWER

I found this which explained that the InputStream has to be created by me. It makes sense that I create an InputStream from the file that I want the user to download and then pass the Stream to the result. I guess that's my answer.

0
AudioBubble On

Inputname defines the name of the method that outputs the "stream"

public InputStream getInputStream () { return new ByteArrayInputStream ( _bytes ); }

0
AudioBubble On

I believe you have the contentDisposition wrong, it should be:

<param name="contentDisposition">attachment; filename="${filename}"</param>

(Chris)