It's been very enlightening! Thank you very much. Cheers, Jerry
On Jan 28, 1:13 pm, Dalius Dobravolskas <[EMAIL PROTECTED]> wrote: > jerryji wrote: > > Dear Pyloners, > > > Greatly appreciated if someone can shed some light on how to return a > > byte stream from my controller. > > > For example, I want /image/123 to return an image so that it could be > > referenced in another page as <img src="/image/123" alt="123" /> > > > (similar discussion did appear before -- > >http://groups.google.com/group/pylons-discuss/msg/f87e2754e6004cb9 > > but doesn't seem to have an answer...) > > I use following: > > class JpegFileApp(DataApp): > """ Jpeg file serving. """ > > def __init__(self, filename, content, **kwargs): > self.filename = filename > kwargs['content_type'] = 'image/jpeg' > DataApp.__init__(self, content, None, **kwargs) > self.content_disposition(filename=filename) > > def guess_type(self): > return 'image/jpeg' > ... > # Somewhere in your controller > def cover(self, id): > ... > app = JpegFileApp(id, image_bytes) > return app(request.environ, self.start_response) > > Technically you can return image as string and set proper Content-type > in response.headers. E.g: > > response.headers['Content-type'] = 'image/jpeg' > return image_bytes > > but it was very slow for me. Not sure why. > > Regards, > Dalius --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
