You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Jakub Kaniewski <jk...@egonet.pl> on 2002/09/14 20:02:00 UTC

Turbine+Velocity + image from database?

I have database with blob field with jpg images. My question is how can I
force Velocity to produce my image. In PHP it was easy
<content-type=jpg>
echo $blobfield
But in Velocity it always add a html header. Do you know solution?
Mayby I must create a special Image template?

J. Kaniewski
jkan@egonet.pl


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Turbine+Velocity + image from database?

Posted by Jeff Jones <jj...@trap9.com>.
Here's what I use.
--
Jeff


public class AssetsGet extends RawScreen {
    
    public String getContentType(RunData data) {
        String contentType = "application/octet-stream";
        try {
            Assets asset =
AssetManager.getAsset(data.getParameters().getInt("id"));
            // save this data in request for use below in doOutput
            data.getRequest().setAttribute("asset", asset);
            contentType = asset.getContenttype().toString();
        } catch(Exception ignored) {
            Log.warn("Asset " + data.getParameters().getInt("id") + "
couldn't be found in AssetsGet!");
        }
        return contentType;
    }
    
    public void doOutput(RunData data) {
        data.declareDirectResponse();
        
        try {
            Assets asset = (Assets)
data.getRequest().getAttribute("asset");
            data.getResponse().setHeader("Content-disposition",
"filename=" + asset.getFilename());
            data.getResponse().setHeader("Content-Type",
asset.getContenttype().toString());
            data.getResponse().setIntHeader("Content-length",
asset.getAsset().length);
           
data.getResponse().getOutputStream().write(asset.getAsset());
        } catch(Exception e) {
            Log.warn("Exception outputting asset: " + e);
        }
    }
}



On Sun, 2002-09-15 at 09:42, Derick wrote:
> 
> ----- Original Message -----
> From: "Derick" <de...@xenocex.com>
> To: "Turbine Users List" <tu...@jakarta.apache.org>
> Sent: Sunday, September 15, 2002 9:40 AM
> Subject: Re: Turbine+Velocity + image from database?
> 
> 
> > Hello,
> >
> > Try something like: data.getResponse().setContentType().
> > And there is also another method
> 
> err class i meant :).
> 
> > org.apache.turbine.modules.screens.RawScreen that might be of use.
> >
> > Hope that helps.
> >
> > ----- Original Message -----
> > From: "Jakub Kaniewski" <jk...@egonet.pl>
> > To: <tu...@jakarta.apache.org>
> > Sent: Saturday, September 14, 2002 11:02 AM
> > Subject: Turbine+Velocity + image from database?
> >
> >
> > > I have database with blob field with jpg images. My question is how can
> I
> > > force Velocity to produce my image. In PHP it was easy
> > > <content-type=jpg>
> > > echo $blobfield
> > > But in Velocity it always add a html header. Do you know solution?
> > > Mayby I must create a special Image template?
> > >
> > > J. Kaniewski
> > > jkan@egonet.pl
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > >
> > >
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Turbine+Velocity + image from database?

Posted by Derick <de...@xenocex.com>.
----- Original Message -----
From: "Derick" <de...@xenocex.com>
To: "Turbine Users List" <tu...@jakarta.apache.org>
Sent: Sunday, September 15, 2002 9:40 AM
Subject: Re: Turbine+Velocity + image from database?


> Hello,
>
> Try something like: data.getResponse().setContentType().
> And there is also another method

err class i meant :).

> org.apache.turbine.modules.screens.RawScreen that might be of use.
>
> Hope that helps.
>
> ----- Original Message -----
> From: "Jakub Kaniewski" <jk...@egonet.pl>
> To: <tu...@jakarta.apache.org>
> Sent: Saturday, September 14, 2002 11:02 AM
> Subject: Turbine+Velocity + image from database?
>
>
> > I have database with blob field with jpg images. My question is how can
I
> > force Velocity to produce my image. In PHP it was easy
> > <content-type=jpg>
> > echo $blobfield
> > But in Velocity it always add a html header. Do you know solution?
> > Mayby I must create a special Image template?
> >
> > J. Kaniewski
> > jkan@egonet.pl
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Turbine+Velocity + image from database?

Posted by Derick <de...@xenocex.com>.
Hello,

Try something like: data.getResponse().setContentType().
And there is also another method
org.apache.turbine.modules.screens.RawScreen that might be of use.

Hope that helps.

----- Original Message -----
From: "Jakub Kaniewski" <jk...@egonet.pl>
To: <tu...@jakarta.apache.org>
Sent: Saturday, September 14, 2002 11:02 AM
Subject: Turbine+Velocity + image from database?


> I have database with blob field with jpg images. My question is how can I
> force Velocity to produce my image. In PHP it was easy
> <content-type=jpg>
> echo $blobfield
> But in Velocity it always add a html header. Do you know solution?
> Mayby I must create a special Image template?
>
> J. Kaniewski
> jkan@egonet.pl
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>