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