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 <j...@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-unsubscr...@struts.apache.org > > For additional commands, e-mail: user-h...@struts.apache.org > > > >
package <snip>.photo.web.actions; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import com.opensymphony.xwork2.ActionSupport; <snip> </snip> @Results ( { @Result(name = "success", location = "downloadPage", type = "tiles"), @Result(name = "error", location = "error", type = "tiles"), @Result(name = "download", type = "stream", params = { "contentType", "application/octet-stream", "inputName", "fileInputStream", "bufferSize", "1024" } ) } ) public class DownloadAction extends ActionSupport { <snip> </snip> /** * Creates a <tt>DownloadAction</tt> object. */ public DownloadAction() { super(); } /** * TODO Add description * * @return The result, which will determine what action or JSP will be * called after execution of the method. */ // TODO Add @Validations, as needed. public String execute() { // NOTE: The execute() method is the default one called by Struts 2 if // the action name matches the class name, where camel-case names are // converted to dashes. See // http://struts.apache.org/2.1.6/docs/convention-plugin.html for more // information. // Initialize the forward name with the "success" value. String forward = "success"; try { // TODO Finish implementing this method (e.g., add a service call). Image imagePhoto = fetchImageByEmployeeId(identifier); ByteArrayInputStream fileInputStream = new ByteArrayInputStream(imagePhoto.getPhotoImage()); forward = "download"; } catch (Exception e) { LOGGER.error("Caught an error while executing the action.", e); } return forward; <snip> </snip> /** * inputStream - Used to return the photo image */ private ByteArrayInputStream fileInputStream; /** * @return the fileInputStream */ public InputStream getFileInputStream() { return fileInputStream; } /** * @param inputStream the inputStream to set */ public void setFileInputStream(ByteArrayInputStream fileInputStream) { this.fileInputStream = fileInputStream; } <snip> </snip> }
--------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org