You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "John W. Himpel" <jo...@jlhimpel.net> on 2012/02/23 22:23:50 UTC

Download a byteArray (jpg image) to browser

Good afternoon,

I have retrieved a jpg image as a byteArray from a database but I don't
know how to put the contents of the byteArray into a FileInputStream to
be sent back to the browser.  I am using the Struts 2 StreamResult for
the data transfer to the browser (Question: Am I trying to put a square
peg into a round hole?).  I would prefer not store the byteArray into a
temporary file and then give the StreamResult a pointer to the temporary
file.  The desired end result is the ability for the user to extract a
jpg file from the database and store it on their local workstation.

Any suggestions or referrals would be greatly appreciated.

John



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Download a byteArray (jpg image) to browser

Posted by Dave Newton <da...@gmail.com>.
+1; those pesky locals not being properties.

On Fri, Feb 24, 2012 at 9:22 AM, Johannes Geppert <jo...@apache.org> wrote:

> The Problem is followinmg Line:
>
>            ByteArrayInputStream fileInputStream = new
> ByteArrayInputStream(imagePhoto.getPhotoImage());
>
> this should be
>
>            this.fileInputStream = new
> ByteArrayInputStream(imagePhoto.getPhotoImage());
>
> Johannes
>
> -----
> web: http://www.jgeppert.com
> twitter: http://twitter.com/jogep
> --
> View this message in context:
> http://struts.1045723.n5.nabble.com/Download-a-byteArray-jpg-image-to-browser-tp5509528p5512933.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [Resolved] Download a byteArray (jpg image) to browser

Posted by "John W. Himpel" <jo...@jlhimpel.net>.
"I see" exclaimed the blind man.

Thanks go to Johannes.

John

On Fri, 2012-02-24 at 06:22 -0800, Johannes Geppert wrote:
> The Problem is followinmg Line:
> 
>             ByteArrayInputStream fileInputStream = new
> ByteArrayInputStream(imagePhoto.getPhotoImage());
> 
> this should be
> 
>             this.fileInputStream = new
> ByteArrayInputStream(imagePhoto.getPhotoImage());
> 
> Johannes
> 
> -----
> web: http://www.jgeppert.com
> twitter: http://twitter.com/jogep
> --
> View this message in context: http://struts.1045723.n5.nabble.com/Download-a-byteArray-jpg-image-to-browser-tp5509528p5512933.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Download a byteArray (jpg image) to browser

Posted by Johannes Geppert <jo...@apache.org>.
The Problem is followinmg Line:

            ByteArrayInputStream fileInputStream = new
ByteArrayInputStream(imagePhoto.getPhotoImage());

this should be

            this.fileInputStream = new
ByteArrayInputStream(imagePhoto.getPhotoImage());

Johannes

-----
web: http://www.jgeppert.com
twitter: http://twitter.com/jogep
--
View this message in context: http://struts.1045723.n5.nabble.com/Download-a-byteArray-jpg-image-to-browser-tp5509528p5512933.html
Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Download a byteArray (jpg image) to browser

Posted by "John W. Himpel" <jo...@jlhimpel.net>.
Johannes;

Thanks for your response.

I have attached:
DownloadAction.java
struts.xml
tiles-def.xml
web.xml

If you need anything else, please let me know.

John

On Thu, 2012-02-23 at 23:13 -0800, Johannes Geppert wrote:
> Hi John,
> 
> can you share the Code of your Action and the configuration for this Action?
> 
> Johannes
> 
> -----
> web: http://www.jgeppert.com
> twitter: http://twitter.com/jogep
> --
> View this message in context: http://struts.1045723.n5.nabble.com/Download-a-byteArray-jpg-image-to-browser-tp5509528p5511883.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


Re: Download a byteArray (jpg image) to browser

Posted by Johannes Geppert <jo...@apache.org>.
Hi John,

can you share the Code of your Action and the configuration for this Action?

Johannes

-----
web: http://www.jgeppert.com
twitter: http://twitter.com/jogep
--
View this message in context: http://struts.1045723.n5.nabble.com/Download-a-byteArray-jpg-image-to-browser-tp5509528p5511883.html
Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Download a byteArray (jpg image) to browser

Posted by "John W. Himpel" <jo...@jlhimpel.net>.
Dave,

Thanks for the suggestion, but either that doesn't work or I'm doing
something quite wrong (A wise person would bet on the latter).

I have attached a snipped version of my Action.java.  When I run it, I
get the following error message:

[ERROR]~2012-02-23-22.18.52.412UTC~EDJ~Can not find a
java.io.InputStream with the name [fileInputStream] in the invocation
stack. Check the <param name="inputName"> tag specified for this action.

According to the javadocs. ByteArrayInputStream extends
java.io.InputStream.

John

On Thu, 2012-02-23 at 16:33 -0500, Dave Newton wrote:
> Use a ByteArrayInputStream [1]?
> 
> Dave
> 
> [1]
> http://docs.oracle.com/javase/6/docs/api/java/io/ByteArrayInputStream.html
> 
> On Thu, Feb 23, 2012 at 4:23 PM, John W. Himpel <jo...@jlhimpel.net> wrote:
> 
> > Good afternoon,
> >
> > I have retrieved a jpg image as a byteArray from a database but I don't
> > know how to put the contents of the byteArray into a FileInputStream to
> > be sent back to the browser.  I am using the Struts 2 StreamResult for
> > the data transfer to the browser (Question: Am I trying to put a square
> > peg into a round hole?).  I would prefer not store the byteArray into a
> > temporary file and then give the StreamResult a pointer to the temporary
> > file.  The desired end result is the ability for the user to extract a
> > jpg file from the database and store it on their local workstation.
> >
> > Any suggestions or referrals would be greatly appreciated.
> >
> > John
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >


Re: Download a byteArray (jpg image) to browser

Posted by Dave Newton <da...@gmail.com>.
Use a ByteArrayInputStream [1]?

Dave

[1]
http://docs.oracle.com/javase/6/docs/api/java/io/ByteArrayInputStream.html

On Thu, Feb 23, 2012 at 4:23 PM, John W. Himpel <jo...@jlhimpel.net> wrote:

> Good afternoon,
>
> I have retrieved a jpg image as a byteArray from a database but I don't
> know how to put the contents of the byteArray into a FileInputStream to
> be sent back to the browser.  I am using the Struts 2 StreamResult for
> the data transfer to the browser (Question: Am I trying to put a square
> peg into a round hole?).  I would prefer not store the byteArray into a
> temporary file and then give the StreamResult a pointer to the temporary
> file.  The desired end result is the ability for the user to extract a
> jpg file from the database and store it on their local workstation.
>
> Any suggestions or referrals would be greatly appreciated.
>
> John
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>