如何修改 blobstoreuploadhandler 以承认状态 200?
据说 GAE SDK 1.5.4 已经删除了 blobstoreuploadhandler 必须返回重定向的要求,并且在生产中据说已经这样了,以便处理程序可以使用模板变量对模板做出“常规”响应。我需要 dev_appserver 具有此功能,因此询问如何修改 dev_appserver 以允许处理程序使用模板变量呈现模板。我想我需要更改的代码在文件中 http://code.google .com/p/googleappengine/source/browse/trunk/python/google/appengine/tools/dev_appserver_blobstore.py 但我不确定要修改什么。您能告诉我如何使处理程序能够定期响应吗?
def EndRedirect(self, redirected_outfile, original_outfile):
"""Handle the end of upload complete notification.
Makes sure the application upload handler returned an appropriate status
code.
"""
response = dev_appserver.RewriteResponse(redirected_outfile)
logging.info('Upload handler returned %d', response.status_code)
if (response.status_code in (301, 302, 303) and
(not response.body or len(response.body.read()) == 0)):
contentless_outfile = cStringIO.StringIO()
contentless_outfile.write('Status: %s\n' % response.status_code)
contentless_outfile.write(''.join(response.headers.headers))
contentless_outfile.seek(0)
dev_appserver.URLDispatcher.EndRedirect(self,
contentless_outfile,
original_outfile)
else:
logging.error(
'Invalid upload handler response. Only 301, 302 and 303 '
'statuses are permitted and it may not have a content body.')
original_outfile.write('Status: 500\n\n')
更新:解决方案已发布在此链接 https:// groups.google.com/forum/#!topic/google-appengine-python/vnvhUG1-UN0
It's said that GAE SDK 1.5.4 has removed the requirement that blobstoreuploadhandler must return a redirect and on production it's supposedly already so that the handler can make a "regular" response to a template with template variables. I need this capability with dev_appserver and therefore ask how I can modify the dev_appserver to admit the handler to render a template with template variables. I suppose that code I need to change is in the file
http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/tools/dev_appserver_blobstore.py
but I'm not sure what to modify. Can you tell me how to make the handler capable of a regular response?
def EndRedirect(self, redirected_outfile, original_outfile):
"""Handle the end of upload complete notification.
Makes sure the application upload handler returned an appropriate status
code.
"""
response = dev_appserver.RewriteResponse(redirected_outfile)
logging.info('Upload handler returned %d', response.status_code)
if (response.status_code in (301, 302, 303) and
(not response.body or len(response.body.read()) == 0)):
contentless_outfile = cStringIO.StringIO()
contentless_outfile.write('Status: %s\n' % response.status_code)
contentless_outfile.write(''.join(response.headers.headers))
contentless_outfile.seek(0)
dev_appserver.URLDispatcher.EndRedirect(self,
contentless_outfile,
original_outfile)
else:
logging.error(
'Invalid upload handler response. Only 301, 302 and 303 '
'statuses are permitted and it may not have a content body.')
original_outfile.write('Status: 500\n\n')
Update: The solution was posted at this link https://groups.google.com/forum/#!topic/google-appengine-python/vnvhUG1-UN0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案已发布,我可以验证这是否有效:
The solution was posted and I could verify that this worked: