You can use anything you want to identify the file to be downloaded. It is
just a parameter on the URL that your Download.java class will look at to
identify what file to download.

We have a file manager service that tracks files by ID (a number that we
assign) and does a security check to make sure that the person requesting
the file is allowed to see that file. That is why we pass in the file ID as
a number on the URL.

If you want to use the actual file name (or path) on the URL, that is up to
you. Just keep in mind any security issues that might come up if anyone can
request any file just by specifying its name on the URL!

Kevin

-----Original Message-----
From: apdas [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 01, 2002 8:44 PM
To: Turbine Users List
Subject: Re: How to server files


Hi Kevin,

Could you please tell whether fileID means full path to the file or
something else ?

I want to pass file name as parameter. Where should I pass that ?

Regards,
A.P.Das.

Kevin Rutherford wrote:
> 
> Hi Fred,
> 
> You should not use a template (.vm) file because your extension of
RawScreen
> is a "complete" response to a page request in Turbine. To access it, the
URL
> should look something like:
> 
>   http://<server>:8080/app/servlet/app?screen=Download&fileID=12345
> 
> Note the use of "screen" instead of "template", which tells Turbine to
> execute ONLY a screen class.
> 
> To force the browser to display a "Save As" dialog box, you can set the
> content type to something that will not be recognized by the browser. For
> example, if your application is called "fred", you could return a content
> type of "application/fred-download" or something like that. If you want
the
> browser to handle the file in some other way, such as displaying it in the
> browser window or launching a helper app, make sure you send the
appropriate
> content type for the file, such as "text/plain" or "application/ms-word",
or
> whatever.
> 
> doOutput() looks something like this (but with exception handling, of
> course):
> 
>   public void doOutput(RunData data)
>     throws Exception
>   {
>     // get the full path to the input file, based on the fileID, or
whatever
> you use
>     // to indicate what file is to be downloaded
> 
>     String filePath = ...
> 
>     // open the file for reading
> 
>     FileInputStream input = new FileInputStream(filePath);
> 
>     // open the response stream
> 
>     ServletOutputStream output = data.getResponse().getOutputStream();
> 
>     // tell the browser what the file name is so that the "save as" dialog
> does the
>     // right thing (use the file name only, not the full path to the
file!)
> 
>     String fileName = ...
>     data.getResponse().setHeader("Content-Disposition", "inline;
filename="
> + fileName);
> 
>     // copy the file content to the response stream
>     // copy the file content from the input stream to the output stream
> 
>     int readCount;
>     byte fileBuffer[] = new byte[FILE_BUFFER_SIZE];
> 
>     while((readCount = input.read(fileBuffer)) != -1)
>     {
>       output.write(fileBuffer, 0, readCount);
>     }
> 
>     // close everything
> 
>     output.flush();
>     output.close();
>     input.close();
>   }
> 
> Hope that helps.
> 
> Kevin
>

--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

Reply via email to