tom*_*low 1 python file-io google-app-engine
我正在使用以下代码:
class Image(webapp.RequestHandler):
def get(self, id):
path = os.path.join(os.path.dirname(__file__), 'fcimages/%s.png' % id)
self.response.headers['Content-Type'] = 'image/png'
print file(path,'rb').read()
Run Code Online (Sandbox Code Playgroud)
它在本地工作正常(即返回图像),但当我在实时服务器上使用它时,我得到了垃圾.你可以在这里看到输出:http://1.ge0.co/fc/1.png
我究竟做错了什么?
谢谢!
PS - 我知道这不是最强大的代码,但它只用于我的内部项目,它不是按比例建立的.
我最终设法解决了这个问题,我认为问题是self.response和print的结合.这是有效的代码:
class Image(webapp.RequestHandler):
def get(self, id):
path = os.path.join(os.path.dirname(__file__), 'fcimages/%s.png' % id)
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(file(path, 'rb').read())
Run Code Online (Sandbox Code Playgroud)