You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mike Elliott <mr...@bcstec.ca.boeing.com> on 2004/09/17 04:26:16 UTC

Making a file available?

I have an application which gathers information about internal
processes.  Some of this information is in the form of a text file, an
Excel file, a PDF file, etc.

What I need to be able to do is to make a URL available to users which
will provide a requested file to a user; that is, if the URL refers to a
PDF file then when a user makes that request, his browser will detect
that the request was for a PDF file and properly render it in xpdf or
acrobat or whatever.

For example, if a user entered the url
 
http://www.blip.org/getFile.do?name=xyz.pdf 

the result would be his browser properly displaying the contents of
xyz.pdf.

Is this even possible?  If so, how would I go about doing it?  We can
assume that the server knows where to find any named file and
furthermore that it knows the MIME type of the file (in this case
application/x-pdf).

Any ideas?




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


Re: Making a file available?

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Read the file from its location into a byte[]  in your Action and then write
the bytes to the response stream and return null from the Action's execute
method (rather than an ActionForward).

byte[] buffer ....// read file into a byte[]

response.setContentType("application/x-pdf");
response.setContentLength(buffer.length);
response.setHeader("Content-disposition", "inline; filename=xyz.pdf");

ServletOutputStream output = response.getOutputStream();
output.write(buffer);
output.flush();

return null;


Niall

----- Original Message ----- 
From: "Mike Elliott" <mr...@bcstec.ca.boeing.com>
To: <us...@struts.apache.org>
Sent: Friday, September 17, 2004 3:26 AM
Subject: Making a file available?


> I have an application which gathers information about internal
> processes.  Some of this information is in the form of a text file, an
> Excel file, a PDF file, etc.
>
> What I need to be able to do is to make a URL available to users which
> will provide a requested file to a user; that is, if the URL refers to a
> PDF file then when a user makes that request, his browser will detect
> that the request was for a PDF file and properly render it in xpdf or
> acrobat or whatever.
>
> For example, if a user entered the url
>
> http://www.blip.org/getFile.do?name=xyz.pdf
>
> the result would be his browser properly displaying the contents of
> xyz.pdf.
>
> Is this even possible?  If so, how would I go about doing it?  We can
> assume that the server knows where to find any named file and
> furthermore that it knows the MIME type of the file (in this case
> application/x-pdf).
>
> Any ideas?



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