Thanks Travis, that helped ;), but it's still not working 100%. The 
save-as dialog pops up and allows me to save to disk, but if I choose to 
open instread of save it hangs. The browser indicates it's busy, but the 
image is never displayed. This only applies to IE, Netscape 6 doesn't 
prompt to save at all. I'll include the complete code below.

Thanks again, Mike


public class FileDownload extends java.lang.Object {
  
   private PageContext pageContext;
   private HttpServletResponse response;
  
   /** Creates new FileDownload */
   public FileDownload() {
       response = null;
   }
  
   public void initialize(PageContext pageContext, HttpServletResponse 
response) {
       this.response = response;
       this.pageContext = pageContext;
   }
  
   public void downloadFile(String filePath, String mimeType, String 
promptName) {
      
       ServletResponse res = pageContext.getResponse();
      
       System.out.println("PATH: " + filePath);
      
       File f = new File(filePath);
       InputStream in = null;
       try {
           in = new BufferedInputStream(new FileInputStream(f));
       } catch (FileNotFoundException e) {
           System.out.println("Unable to open " + filePath + " for 
download!");
           return;
       }
      
       response.setContentType("image/gif");
       response.setContentLength((int) f.length());
       response.setHeader("Content-disposition","attachment; filename=" 
+ promptName);
       OutputStream out = null;
       try {
           out = res.getOutputStream();
       } catch (IOException e) {
           System.out.println("Error opening output stream in 
FileDownload!");
           return;
       }
       int  sentsize = 0;
       int  readlen;
       byte buffer[] = new byte[256];
      
       try {
           while ((readlen = in.read(buffer)) != -1 ) {
               out.write(buffer, 0, readlen);
               sentsize += readlen;
           }
       } catch (IOException e) {
           System.out.println("Error transfering file in FileDownload!");
           return;
       }
       // Success ! Close streams.
       try {
           out.flush();
           out.close();
           in.close();
       } catch (IOException e) {
       }
   }
}



[EMAIL PROTECTED] wrote:

> You spelt attachment wrong.  You have attachement.
> 
> Travis
> 
> ---- Original Message ----
> From: Mike Tinnes <[EMAIL PROTECTED]>
> Sent: 2001-01-19 23:45:17.0
> To: [EMAIL PROTECTED]
> Subject: file upload issues
> 
> Hello everyone. I need a jsp which downloads a serverside image to a client and 
>instead of simply displaying the image in the browser, I'd like it to popup a save-as 
>dialog. I've read a few posts on a similar subject, but I can't get anything to work 
>the way I need it to. I've tried the following in my response code...
> 
>         response.setContentType("image/gif");
>         response.setContentLength((int) f.length());
>         response.setHeader("Content-disposition","attachement; filename=test.gif");
> 
> This displays the image in the browser as usual, but does use 'test.gif' for saving. 
>Do I need some special mime type? 
> 
> TIA, Mike
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to