Thanks, Ian - that worked! @Marco: Thanks for the alternative technique - I think I like the idea of using StringIO and not creating/ deleting the file.
On Dec 2, 4:20 pm, Ian Wilson <[email protected]> wrote: > Seems that you want something like this when using StringIO (in python 2.6 > at least): > > try: > return f.getvalue() > finally: > f.close() > > On Thu, Dec 2, 2010 at 2:33 PM, [email protected] < > > [email protected]> wrote: > > I want my controller to return a UPC barcode as action with one > > argument, like so: mycontroller/barcode/012345678901 > > > It works fine if I read a file object, like so: > > > def barcode(self, data): > > f = open('barcode.jpg', 'r') > > barcode_('upc-a', str(data)).save(f, format='JPEG') > > response.headers['Content-Type'] = 'image/jpg' > > f.close() > > f.open('barcode.jpg') > > return f.read() > > > But I don't want to do that because then I have a bunch of temp files > > to clean up. But using StringIO just gives me the URL in the browser > > window (no image): > > > def barcode(self, data): > > import StringIO > > f = StringIO.StringIO() > > barcode_('upc-a', str(data)).save(f, format='JPEG') > > response.headers['Content-Type'] = 'image/jpg' > > return f.buff > > > Any tips on how to render an image like this without writing/reading > > the persisted file would be helpful. Thanks. > > > -- > > 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]<pylons-discuss%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/pylons-discuss?hl=en. -- 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.
