[Zope3-dev] Returning large amounts of data to a client
Peter Mayne
PeterMayne at ap.spherion.com
Tue Jan 4 22:35:16 EST 2005
I have a resource class that returns binary data (PNG images in this
case) to the client, along the following lines:
class MyResource(BrowserView, Resource):
implements(IBrowserPublisher)
...
def GET(self):
request = self.request
response = request.response
response.setHeader('Content-Type', CONTENT_TYPE)
data = /generate binary data here/
return data
This is fine when the amount of data is small, but what if there are
many bytes involved.
The obvious thing to try was
response.write(data)
return None
and guessing that I can write a sequence of (say) 64KB chunks so I don't
use too much memory, but I get
File "C:\opt\Python23\Lib\site-packages\zope\server\buffers.py", line
186, in append
self.strbuf = strbuf + s
UnicodeDecodeError: 'ascii' codec can't decode byte 0x89 in position
283: ordinal not in range(128)
which implies that ZX3 is expecting (possibly UTF-8) encoded characters,
rather than binary data, when writing to the response. Furthermore, I
possibly wouldn't want to buffer the large amount of data, which is what
the classes in buffers.py seem to do.
What is the right thing to do when returning potentially large amounts
of data to a client?
Thanks.
PJDM
--
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"I'm after rebellion, I'll settle for lies" - Blue Oyster Cult
More information about the Zope3-dev
mailing list