Can't you just cache the result of the f.read() call, delete the file
and then return from the call?

        f.close()
        f.open('barcode.jpg')
        tmp = f.read()
        os.remove('barcode.jpg') # should really create a unique temp
name to avoid concurrency problems


On Dec 2, 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].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to