Your last option is what would be considered best practice. Set the headers
correctly and return the content of the binary as your response.

On Wed, May 11, 2011 at 11:24 AM, David Buchmann <david.buchm...@liip.ch>wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> hi,
>
> i have binary content that i have to deliver to the client. what is the
> right way to do it? i found two solutions, but neither seems really good.
>
>
>
> //in my controller, i get a binary stream (its stored in the database)
>
> $picture = $this->method_that_returns_resource_stream();
>
> // i can just use plain php and dump and die. not nice.
> header('Content-Type: image/jpeg');
> fpassthru($picture);
> die;
>
>
> /*
> or i can use a response, but then i have to read the stream into memory,
> which is unefficient.
> */
>
> $response = new Response(stream_get_contents($picture));
> $response->headers->set('Content-Type', 'image/jpeg');
> return $response;
>
>
> cheers,
> david
>
> - --
> Liip AG // Agile Web Development // T +41 26 422 25 11
> CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk3KVdoACgkQqBnXnqWBgIsIGQCgjmrKIolRlfp3cvXG53kFDzYe
> n+8AmwYrR7y7GPsvkK5MoiTpP3xTWJa+
> =8FYf
> -----END PGP SIGNATURE-----
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to symfony-users@googlegroups.com
> To unsubscribe from this group, send email to
> symfony-users+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>



-- 
Gareth McCumskey
http://garethmccumskey.blogspot.com
twitter: @garethmcc
identi.ca: @garethmcc

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to