I figured it out the reason is the package I used, pyfilesystem, http://code.google.com/p/pyfilesystem/
I used the RemoteFileBuffer. Now, I use RemoteFileBuffer._read() to get out the local buffer object which makes the Response.body happy. Thanks a lot for all the helps! -Shu On Sunday, December 30, 2012 6:13:39 PM UTC-8, Shu Lin wrote: > > Hi, > > If I have other objects other than String, which is holding a jpg or png > file, I like to return it as Response body, how can I do? > > I tried a piece of code like this: > > mimetype = image/png > body = fs.open(access_path, 'rb') > > return Response(body, content_type=mimetype) > > Here "body" is an buffer object from a kind of filesystem which represents > the content in the file. Since, it doesn't support len() like String. I > can't passed the Response check for len(). I tried app_iter also like this: > > return Response(app_iter=[body], content_type=mimetype) > > But, if I did like this, the wsgiref will complain about the body is not > String type. > > =========== > > 2012-12-29 23:33:59,521 INFO [fs.tahoelafs][MainThread] (4363489744) > Opening file /family/Ada/IMG_0355.JPG in mode rb > > Traceback (most recent call last): > > File > "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", > > line 86, in run > > self.finish_response() > > File > "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", > > line 127, in finish_response > > self.write(data) > > File > "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", > > line 202, in write > > assert type(data) is StringType,"write() argument must be string" > > AssertionError: write() argument must be string > > ========== > > Is there anyway to work around this? > > Thanks a lot in advance! > > -Shu > -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To view this discussion on the web visit https://groups.google.com/d/msg/pylons-devel/-/eyMpBjKGuNsJ. To post to this group, send email to pylons-devel@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.