作为我问的另一个问题的后续,我有一个基本问题,即获取WebApp2 Python服务器的最简单方法,以提供太大的JSON数据(约100 kb)作为通道API消息发送给客户端。
WebApp2服务器基于客户端请求在几分钟内生成多个数据文件,我想我希望Channel API在数据准备就绪时将消息与客户端发送给客户端和客户端(aGWT应用程序)可以执行HTTP获取请求以获取数据。每个数据文件都是客户端独有的,因此服务器必须具有一个请求处理程序,该请求处理程序将为客户端提供适当的数据文件。
您可以编写一个请求处理程序,该请求处理程序可以在调用请求时直接从另一个请求处理程序提供正确的数据文件?还是我需要先使用Cloud SQL或数据存储来存储数据,直到客户端要求它?这是我想做的一些不完整的示例代码:
class MainPage(webapp2.RequestHandler):
def get(self):
## This opens the GWT app
class Service_handler(webapp2.RequestHandler):
def get(self, parameters):
## This is called by the GWT app and generates the data to be
## sent to the client.
## A channel API message is sent to the client with the url
## for each data file generated.
class kml_handler(webapp2.RequestHandler):
def get(self, client_id):
## I would like to return the correct data here when it is
## called by the client. Do I need to store the data in
## Cloud SQL or the Data Store and then retrieve it
## or can this handler take the results directly from the
## Service_handler as soon as it is generated?
app = webapp2.WSGIApplication([
webapp2.Route(r'/', handler=MainPage),
webapp2.Route(r'/Service/', handler=Service_handler),
webapp2.Route(r'/_ah/channel/<connected>/', handler = connection_handler),
webapp2.Route(r'/kml/<client_id>', handler = kml_handler)
],
debug=True)
您可以将文件写入BlobStore,并从BlobStore中提供这些文件。
这是一个示例:https://developers.google.com/appengine/docs/python/blobstore/overview#complete_sample_app