Anthony, I had thought that the actual content of the stream was used in the hash. But, reading your response, it seems that's not the case (and in fact why would it). I will endevour to perhaps write the header record in the csv, then insert into the upload table, and then write the bulk of the csv content. That saves the processing and storage issues.
Simone, your response appears to be very elegant, thanks. I will have to figure out the likely max report size in case I run into memory issues (assuming the cStringIO holds the data in memory). These are excellent responses, thanks to both. I will dip my toe in the water on these before commenting further. Given these responses, I am kind of assuming that using the uploads folder in the way I suggested is the right way to go. Simon On Wednesday, August 7, 2013 9:03:53 PM UTC+1, Niphlod wrote: > > you can pass a StringIO instance instead of the open(filename, 'rb') .... > To avoid the double-pass just create the csv as a StringIO stream and > insert it directly into the table with the db.tablename.field.store() as > the example you posted: web2py will save the file into the uploads/ folder > and no problem with that. > > Untested example: assuming in your "generatecsv" function has something > like.... > destination = open('path_to_file', 'wb') > writer = csv.writer(destination) > writer.writerow(['a', 'row']) > destination.close() > > you can do instead > from cStringIO import StringIO > destination = StringIO() > writer = csv.writer(destination) > writer.writerow(['a', 'row']) > > db.reportcsv.insert(csvfile=db.reportcsv.csvfile.store(destination,'path_to_file'),reportname='report_1') > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.