Hello!
What is the current right way to stream data in web2py?
I'm trying to stream the data using cStringIO and response.stream, but as a best result I get an empty file.
Here is a source snippet:
rows = current.db(current.db.categories.belongs(categories)).select()
s = cStringIO.StringIO()
rows.export_to_csv_file(s, represent=False)
return response.stream(s, attachment=True, filename='categories.csv')
As a result I get an empty csv file, while s did contain the right data.
I couldn't find any clear documentation for response.stream, so I experimented with parameters, but it didn't work.
Do I have to set headers manually? Can I stream cStringIO instead of file object?
PS:
http://web2py.com/examples/static/epydoc/web2py.gluon.globals.Response-class.html#stream and
http://web2py.com/examples/static/epydoc/web2py.gluon.globals-pysrc.html#Response.stream show different default keyword arguments:
stream(self, stream, chunk_size=65536, request=threading.local(), attachment=True, filename=threading.local())
and
def stream( self, stream, chunk_size=DEFAULT_CHUNK_SIZE, request=None, attachment=False, filename=None)
correspondingly.