You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by jfputnam <jo...@comcast.net> on 2009/02/26 20:48:55 UTC

Problem with file download.

I have followed serveral examples but still have an issue downloading a file
using an input stream. In IE7 when I try the download with text/plain
context type, the text is rendered in the html page. When I change the
contentType a file dialog folder pops up with open/open folder/ cancel no
save button.

There is also a popup window that says Internet Explorer cannot download
extractAccounting.action from localhost.  Internet Explorer was not able to
open this Internet site. The requested site is either unavailable or cannot
be found. Please try again later.

On firefox there is no file save dialog, just the text displayed.

I want to be able to generate .csv files and have the user be able to save
them on their pc.

The struts.xml entry is.

        <action name="extractAccounting"
class="com.merrick.bestmatch.presentation.action.billing.AccountingLink"
                method="extractAccounting">
            <result name="success" type="stream">
            document.pdf
            inputStream
            filename="document.pdf"
            1024
            </result>
        </action>


The action class is:


public class AccountingLink extends BestMatchActionSupport implements
PropertiesAware
{

    private InputStream inputStream;

//----------------------------------------------------------------------------------------------------
public String extractAccounting()
{
    

    String text = "Converting String to InputStream Example";

    try
    {
        inputStream = new ByteArrayInputStream(text.getBytes("UTF-8"));
    }
    catch (UnsupportedEncodingException e)
    {
        e.printStackTrace();
    }


return SUCCESS;

}
//----------------------------------------------------------------------------------------------------
    public InputStream getInputStream()
      {
        return inputStream;
      }

}


Any help with figuring out what the problem is and a solution is
appreciated.

---John Putnam

-- 
View this message in context: http://www.nabble.com/Problem-with-file-download.-tp22232119p22232119.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: Problem with file download.

Posted by Struts Two <st...@yahoo.ca>.
I had the same problem that I used to get prompted for file save on IE6 but on IE7 the attachment was being displayed in a new pop up browser. and I did the following to resolve it:

<action name="ticketFileDownload" class="ccol.action.ticket.TicketFileDownload">
     <result name="success" type="stream">
           <param name="contentType">application/octet-stream</param>
     </result>
</action>

Then make ur action class implement "ServletResponseAware" interface and add the following lines to your action method:

setInputStream(new ByteArrayInputStream(attachment.getAttachment()));
		getServletResponse().setHeader("Content-Disposition",
				("attachment; filename=\"" + attachment.getName() + "\""));

For some reason not known to me, using the above method, you get prompted to save the file in IE6/7 and firefox 2.x and 3.x. However, following the way described in Wiki documentation would result to the problem you are experiencing.


--- On Thu, 2/26/09, Security Management <li...@secmgmt.com> wrote:

> From: Security Management <li...@secmgmt.com>
> Subject: RE: Problem with file download.
> To: "'Struts Users Mailing List'" <us...@struts.apache.org>
> Received: Thursday, February 26, 2009, 8:17 PM
> Here's what I've used, note the contentDisposition.
> 
> <result name="export-image"
> type="stream">
> 	<param
> name="contentType">image/jpg</param>
>       <param
> name="inputName">imageStream</param>
>       <param
> name="contentDisposition">attachment;
> filename="image.jpg"</param>
>       <param
> name="bufferSize">4096</param>
> </result>
> 
> -----Original Message-----
> From: jfputnam [mailto:johnfputnam@comcast.net] 
> Sent: Thursday, February 26, 2009 2:49 PM
> To: user@struts.apache.org
> Subject: Problem with file download.
> 
> 
> I have followed serveral examples but still have an issue
> downloading a file
> using an input stream. In IE7 when I try the download with
> text/plain
> context type, the text is rendered in the html page. When I
> change the
> contentType a file dialog folder pops up with open/open
> folder/ cancel no
> save button.
> 
> There is also a popup window that says Internet Explorer
> cannot download
> extractAccounting.action from localhost.  Internet Explorer
> was not able to
> open this Internet site. The requested site is either
> unavailable or cannot
> be found. Please try again later.
> 
> On firefox there is no file save dialog, just the text
> displayed.
> 
> I want to be able to generate .csv files and have the user
> be able to save
> them on their pc.
> 
> The struts.xml entry is.
> 
>         <action name="extractAccounting"
> class="com.merrick.bestmatch.presentation.action.billing.AccountingLink"
>                 method="extractAccounting">
>             <result name="success"
> type="stream">
>             document.pdf
>             inputStream
>             filename="document.pdf"
>             1024
>             </result>
>         </action>
> 
> 
> The action class is:
> 
> 
> public class AccountingLink extends BestMatchActionSupport
> implements
> PropertiesAware
> {
> 
>     private InputStream inputStream;
> 
> //--------------------------------------------------------------------------
> --------------------------
> public String extractAccounting()
> {
>     
> 
>     String text = "Converting String to InputStream
> Example";
> 
>     try
>     {
>         inputStream = new
> ByteArrayInputStream(text.getBytes("UTF-8"));
>     }
>     catch (UnsupportedEncodingException e)
>     {
>         e.printStackTrace();
>     }
> 
> 
> return SUCCESS;
> 
> }
> //--------------------------------------------------------------------------
> --------------------------
>     public InputStream getInputStream()
>       {
>         return inputStream;
>       }
> 
> }
> 
> 
> Any help with figuring out what the problem is and a
> solution is
> appreciated.
> 
> ---John Putnam
> 
> -- 
> View this message in context:
> http://www.nabble.com/Problem-with-file-download.-tp22232119p22232119.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


      __________________________________________________________________
Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/


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


RE: Problem with file download.

Posted by Security Management <li...@secmgmt.com>.
Here's what I've used, note the contentDisposition.

<result name="export-image" type="stream">
	<param name="contentType">image/jpg</param>
      <param name="inputName">imageStream</param>
      <param name="contentDisposition">attachment;
filename="image.jpg"</param>
      <param name="bufferSize">4096</param>
</result>

-----Original Message-----
From: jfputnam [mailto:johnfputnam@comcast.net] 
Sent: Thursday, February 26, 2009 2:49 PM
To: user@struts.apache.org
Subject: Problem with file download.


I have followed serveral examples but still have an issue downloading a file
using an input stream. In IE7 when I try the download with text/plain
context type, the text is rendered in the html page. When I change the
contentType a file dialog folder pops up with open/open folder/ cancel no
save button.

There is also a popup window that says Internet Explorer cannot download
extractAccounting.action from localhost.  Internet Explorer was not able to
open this Internet site. The requested site is either unavailable or cannot
be found. Please try again later.

On firefox there is no file save dialog, just the text displayed.

I want to be able to generate .csv files and have the user be able to save
them on their pc.

The struts.xml entry is.

        <action name="extractAccounting"
class="com.merrick.bestmatch.presentation.action.billing.AccountingLink"
                method="extractAccounting">
            <result name="success" type="stream">
            document.pdf
            inputStream
            filename="document.pdf"
            1024
            </result>
        </action>


The action class is:


public class AccountingLink extends BestMatchActionSupport implements
PropertiesAware
{

    private InputStream inputStream;

//--------------------------------------------------------------------------
--------------------------
public String extractAccounting()
{
    

    String text = "Converting String to InputStream Example";

    try
    {
        inputStream = new ByteArrayInputStream(text.getBytes("UTF-8"));
    }
    catch (UnsupportedEncodingException e)
    {
        e.printStackTrace();
    }


return SUCCESS;

}
//--------------------------------------------------------------------------
--------------------------
    public InputStream getInputStream()
      {
        return inputStream;
      }

}


Any help with figuring out what the problem is and a solution is
appreciated.

---John Putnam

-- 
View this message in context:
http://www.nabble.com/Problem-with-file-download.-tp22232119p22232119.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