Fabio,
After some experiments, I think there's actually a logical problem with what you're 
trying to do.
If you do Save As from IE or Netscape then the saveas dialog box is displayed before 
the browser
goes to make the request. So there's no way that can work, the link is generated 
correctly

The way to do it might be to redirect a class of URLs (/Download say) to a jsp/java 
and extract the filename from
the
trailing part (PATH_INFO) of the URL, so something like,
    /Download/realfilename.extension
With Download caught (by web.xml I think) and the script picking up the rest to find 
which file to send. Provided
the 'Download' bit looks like a directory to the browsers they will use the other part 
for filename.

(hopefully!)

sorry gtg in a hurry, I'll try and get it to work later.

Fabio Daprile wrote:

> Hello,
>
> I've another little problem regarding download.
> I use a RawScreen (Download.vm) and my files are stored in a MySql DB,
> in a BLOB field.
> It does work when you only display the file, the problem raises when you
> try to save this file.
>
> hereafter how i call that page:
>             <a
> href="$link.setPage("Download.vm").addQueryData("attachid",
> "$Attachment.getId()")">$Attachment.getFilename()</A>
>
> and here how is et the headers:
>
>             resp.setContentType(_attach.getContenttype());
>             resp.setContentLength(_attach.getContent().length);
>             resp.setHeader("Content-Disposition", "attachment");
>             resp.setHeader("filename", _attach.getFilename());
>
> The name of the file becomes "Download", the realname is lost.
>
> How is it possible to keep the name of the file.
>
> Peter Goode wrote:
>
> >John,
> >Gotcha, I was trying to assign it as OutputStream..., presumably that was breaking
> >it (?)
> >
> >Anyway, fixed now following your help... it's amazing how useful it is to be told
> >what you've already read (manual blindness sets in after a while!)
> >
> >
> >Is there a better file upload/download example than the TDK inbuilt app (newapp), as
> >that doesn't have any working download at present,
> >despite the upload. The attached code works ok.
> >
> >
> >Thank you for your help.
> >
> >
> >Peter
> >
> >John McNally wrote:
> >
> >>HttpServletResponse inherits the getOutputStream() method from
> >>ServletResponse.
> >>
> >>Peter Goode wrote:
> >>
> >>>Hi,
> >>>
> >>>I've been trying to get an uploaded file to be sent back...
> >>>
> >>>PROBLEM:
> >>>I can't get binary access to the output stream (from within subclass of
> >>>RawScreen).
> >>>
> >>>I'm using the code below which is reproduced around various Turbine
> >>>sites&mailing lists.
> >>>However, .getOutputStream() doesn't actually exist, according to all
> >>>documentation, and indeed
> >>>it fails to work (although I've not got any debugging, just
> >>>comment/uncomment and see what lives !)
> >>>
> >>>Is anything wrong with this..? (well yes) and why does everyone claim to
> >>>use .getOutputStream() when it doesn't
> >>>exist... ?
> >>>
> >>>If it can be made to work then the Tutorial should be updated, because
> >>>there is no working download file
> >>>in there at present.
> >>>
> >>>Cheers for your help
> >>>
> >>>Peter
> >>>
> >>>/*------/// code starts ///---------*/
> >>>
> >>>public class Download extends RawScreen
> >>>{
> >>>     public void doOutput(RunData data) throws Exception
> >>>     {
> >>>         if (!isAuthorized(data))
> >>>         {
> >>>            // do something to tell the user they don't have permission
> >>>         }
> >>>         else
> >>>         {
> >>>            data.declareDirectResponse();
> >>>            FileInputStream file_tosend = new
> >>>FileInputStream(TurbineServlet.getRealPath("/uploaded.file"));
> >>>            BufferedInputStream buffer_data = new
> >>>BufferedInputStream(file_tosend);
> >>>            // OK to here
> >>>
> >>>            // these 3 would kill it
> >>>            //OutputStream stream_out =
> >>>data.getResponse().getOutputStream();
> >>>            //BufferedOutputStream buffer_out = new
> >>>BufferedOutputStream(stream_out);
> >>>            //buffer_out.write(buffer_data.read());
> >>>
> >>>            // *** *** this one kills it, when enabled *** ***
> >>>            //OutputStream a = data.getResponse().getOutputStream();
> >>>
> >>>            // Will work and do all this, provided the
> >>>.getOutputStream() call isn't made YYY
> >>>            // Documentation for RunData.getResponse() -->
> >>>javax.servlet.http.HttpServletResponse
> >>>            // shows that there is no .getOutputStream() method... what
> >>>should be going on !?
> >>>            String str = "test 9D";
> >>>            PrintWriter out = data.getOut();
> >>>            out.println(str);
> >>>            out.flush();
> >>>            file_tosend.close();
> >>>         }
> >>>     }
> >>>
> >>>     public String getContentType(RunData data)
> >>>     {
> >>>        return "text/html";
> >>>        //return "image/jpeg";
> >>>     }
> >>>
> >>>     protected boolean isAuthorized(RunData data)
> >>>     {
> >>>         // do the security check here.  Get whatever info you need
> >>>         // about the user from RunData
> >>>        return true;
> >>>     }
> >>>}
> >>>/*------/// ends ///---------*/
> >>>
> >>>--
> >>>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> >>>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> >>>
> >>--
> >>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> >>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> >>
> >>
> >>------------------------------------------------------------------------
> >>
> >>package org.mrexcessive.peter1.modules.screens;
> >>
> >>/* ====================================================================
> >> * The Apache Software License, Version 1.1
> >> *
> >> * Copyright (c) 2001 The Apache Software Foundation.  All rights
> >> * reserved.
> >> *
> >> * Redistribution and use in source and binary forms, with or without
> >> * modification, are permitted provided that the following conditions
> >> * are met:
> >> *
> >> * 1. Redistributions of source code must retain the above copyright
> >> *    notice, this list of conditions and the following disclaimer.
> >> *
> >> * 2. Redistributions in binary form must reproduce the above copyright
> >> *    notice, this list of conditions and the following disclaimer in
> >> *    the documentation and/or other materials provided with the
> >> *    distribution.
> >> *
> >> * 3. The end-user documentation included with the redistribution,
> >> *    if any, must include the following acknowledgment:
> >> *       "This product includes software developed by the
> >> *        Apache Software Foundation (http://www.apache.org/)."
> >> *    Alternately, this acknowledgment may appear in the software itself,
> >> *    if and wherever such third-party acknowledgments normally appear.
> >> *
> >> * 4. The names "Apache" and "Apache Software Foundation" and
> >> *    "Apache Turbine" must not be used to endorse or promote products
> >> *    derived from this software without prior written permission. For
> >> *    written permission, please contact [EMAIL PROTECTED]
> >> *
> >> * 5. Products derived from this software may not be called "Apache",
> >> *    "Apache Turbine", nor may "Apache" appear in their name, without
> >> *    prior written permission of the Apache Software Foundation.
> >> *
> >> * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> >> * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> >> * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> >> * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> >> * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> >> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> >> * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> >> * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> >> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> >> * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> >> * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> >> * SUCH DAMAGE.
> >> * ====================================================================
> >> *
> >> * This software consists of voluntary contributions made by many
> >> * individuals on behalf of the Apache Software Foundation.  For more
> >> * information on the Apache Software Foundation, please see
> >> * <http://www.apache.org/>.
> >> */
> >>
> >>import java.util.Vector;
> >>import java.io.FileInputStream;
> >>import java.io.BufferedInputStream;
> >>import java.io.BufferedOutputStream;
> >>import java.io.OutputStream;
> >>import java.io.PrintWriter;
> >>import javax.servlet.ServletOutputStream;
> >>
> >>import org.apache.turbine.modules.screens.RawScreen;
> >>import org.apache.turbine.util.RunData;
> >>
> >>import org.apache.turbine.util.db.Criteria;
> >>import org.mrexcessive.peter1.om.RdfPeer;
> >>import org.apache.turbine.util.upload.FileItem;
> >>import org.apache.turbine.services.servlet.TurbineServlet;
> >>
> >>import org.apache.velocity.context.Context;
> >>
> >>/**
> >>Send back the previously uploaded file, uses RawScreen via Download.vm (?possibly 
>wrong?)
> >> */
> >>public class Download extends RawScreen
> >>{
> >>     public void doOutput(RunData data) throws Exception
> >>     {
> >>         if (!isAuthorized(data))
> >>         {
> >>            // do something to tell the user they don't have permission
> >>         }
> >>         else
> >>         {
> >>            data.declareDirectResponse();
> >>            FileInputStream file_tosend = new 
>FileInputStream(TurbineServlet.getRealPath("/uploaded.file"));
> >>            ServletOutputStream op = data.getResponse().getOutputStream();
> >>            int bufsize = 16384;
> >>            byte [] buf = new byte[bufsize];
> >>            while (file_tosend.available() > 0) {     // belt & braces ? why
> >>               int got = file_tosend.read(buf,0,bufsize);
> >>               if (got != -1) {
> >>                  op.write(buf,0,got);
> >>               }
> >>               else {
> >>                  break;
> >>               }
> >>            }
> >>            op.flush();
> >>         }
> >>     }
> >>
> >>     public String getContentType(RunData data)
> >>     {
> >>        return "image/jpeg";
> >>     }
> >>
> >>     protected boolean isAuthorized(RunData data)
> >>     {
> >>         // do the security check here.  Get whatever info you need
> >>         // about the user from RunData
> >>        return true;
> >>     }
> >>}
> >>
> >>
> >>------------------------------------------------------------------------
> >>
> >>--
> >>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> >>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> >>
>
> --
>
> --
> Fabio Daprile
>
> W�rth-Phoenix Srl
> Via Kravogl 4, I-39100 Bolzano
> Tel: +39 0471/564111 - (direct 564070)
> Fax: +39 0471/564122
>
> mailto:[EMAIL PROTECTED]
> http://www.wuerth-phoenix.com
> http://www.wuerth.com


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

Reply via email to