[Catalyst] internal redirect
Roberto Henríquez
roberto at freekeylabs.com
Wed Apr 11 15:45:22 GMT 2007
Adeola Awoyemi escribió:
> Hi all,
>
> Is there a way to do an internal redirect in Catalyst?
>
> In my application I'm generating images on the fly and want to
> redirect to the image if creation succeeds.
>
> For instance:
>
> $image = Imager->new()
> $image->read( file => $src_file );
> $new_img = $image->copy->scale( xpixels => 32, ypixels => 32 );
> if ( $new_img->write( file => $new_filename ) ) {
> # do internal redirect to new file here
> }
>
> I tried using "$c->response->redirect( $new_filepath )" but that
> issues a 302 "Temporarily Moved" status. But what I actually want is a
> way to do the redirect outside of the response chain.
>
> I hope this is clear?!
Hi,
looks like you want to serve the file directly to the browser.
In order to do that you must output the contents of the file as the
response body:
So, you read the image from the filesystem into $content, and then do
(from a controller action):
$c->res->headers->content_type( 'image/jpeg' );
$c->res->headers->content_length( $length );
$c->res->body($content);
return 1;
Hope this helps!
--R
More information about the Catalyst
mailing list