> -----Original Message-----
> From: Fabio Daprile [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 31, 2002 9:51 AM
> To: Turbine Users List
> Subject: Re: Please help. Content type: Sending pdf content to the browser
> 
> This is how i send files to the browser.
> All documents are stored in a table in MySql, in a blob field.

Isn't this slow?  Why not put them on disk?

> For pdf files the content_type is "application/pdf".

Try "unknown" as a test.  If the url extension is .pdf it will load in
acrobat.

> I use turbine 2.
> 
>  _attach = (Attachments)(_trans.getAttachmentss().elementAt(0));
> 
>  _contentType = _attach.getContenttype() + ";name=" + "\"" +
> _attach.getFilename() + "\"";
>  data.getResponse().setContentType(_contentType);
>  data.getResponse().getOutputStream().write(_attach.getContent());
> 
> hope this can help you.
> 

Something is getting sent prior to your setting the content type, most
likely.

You should buffer this out.  Pass in the servletoutputstreem to something
like:

      /////////////////////////////////////////////////////////
    /**
     * Stream the file since it could be huge.
     */
    public static void bufferItOut( OutputStream out, String fileName ) {

      //p( "serving file" );
      // buffered read of file
      //pBean.setContentType( "application/pdf" );
      //String line = null;
      try {

        //byte[] file_bytes = null;
        File f = new File( fileName );
        final int size = (int)f.length();
        //file_bytes = new byte[size];

        int defBufSize = 8192;
        byte[] b_buf = new byte[defBufSize];

        //ServletOutputStream out = pBean.res.getOutputStream();
        FileInputStream fis = new FileInputStream(f);
        int totalRead = 0;
        try {
          if ( size < defBufSize ) {
            byte[] s_buf = new byte[size - totalRead];
            int read = fis.read(s_buf);
            out.write( s_buf, 0, s_buf.length);
            totalRead = s_buf.length;
          }
          else {
            while ( size - totalRead > 0 ) {
              if ( size - totalRead > defBufSize ) {
                int read = fis.read(b_buf);
                out.write( b_buf, 0, b_buf.length);
                totalRead += defBufSize;
              // data left is less than the buffer
              } else {
                byte[] s_buf = new byte[size - totalRead];
                int read = fis.read(s_buf);
                out.write( s_buf, 0, s_buf.length);
                totalRead += s_buf.length;
              }
            }
          }
        } catch ( Exception e ) {
          log.error( e );
        } finally {
          fis.close();
          //out.close();
        }

      } catch( Exception e ) {
        log.error( e );
      }
    }


> Greetings.
> 
> Fabio Daprile
> 
> Aravinda Addala wrote:
> 
> >Hi,
> >
> >I have read several postings about sending a different content to the
> >browser. I am trying to generate a pdf using FDF in my action. I get the
> >content displayed as plain text. I tried many ways ( I had set the
> content
> >type both in Response and RunData objects in my action. Also tried to use
> >data.setContentType in the template. Nothing worked). The same code works
> >fine if I use that in a Servlet outside turbine.
> >I am using turbine 3.
> >
> >Please help.
> >
> >Thanks in advance.
> >Aravinda
> >
> >
> >
> >--
> >To unsubscribe, e-mail:   <mailto:turbine-user-
> [EMAIL PROTECTED]>
> >For additional commands, e-mail: <mailto:turbine-user-
> [EMAIL PROTECTED]>
> >
> >
> >
> 
> --
> 
> 
> W�rth Phoenix Srl
> Via Kravogl 4, I-39100 Bolzano
> Tel: +39 0471/564111
> Fax: +39 0471/564122
> 
> mailto:[EMAIL PROTECTED]
> http://www.wuerth-phoenix.com
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:turbine-user-
> [EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:turbine-user-
> [EMAIL PROTECTED]>

Reply via email to