[Catalyst] UTF-16 surrogate message when writing binary data (image)

Matt S Trout dbix-class at trout.me.uk
Sat May 10 15:05:39 BST 2008

On Fri, May 09, 2008 at 02:58:41PM +0800, Martin Ellison wrote:
> If I write binary data (a JPEG) using $c->res->body then I get all these
> errors
>  stderr: UTF-16 surrogate 0xdf98 at /usr/lib/perl/5.8/IO/Handle.pm line 199.
> My code looks like
>       $c->res->content_type(q{image/jpeg});
>     $c->res->header( 'Content-Disposition', q{inline} );
>     $c->res->body($pic_image);
> Presumably, something is assuming that the output is Unicode text and trying
> to interpret it accordingly. These error messages are all over the log,
> making it difficult to read, besides any impact the situation may be having
> on the output.
> Is there any way to fix this issue (eg something like binmode)?

My best guess here is that $pic_image is, or looks like, a file handle,
and so when Catalyst is sending the response it's doing so by reading
from the filehandle and the error's turning up during $fh->read.

It'd of course be easier for you to confirm this, since you have the
copy of IO/Handle.pm and the line number - maybe you could look?

A good way to check would be to loop reading $pic_image yourself and
see if you get the same warning ...

      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/

More information about the Catalyst mailing list