作为another question I asked的后续,我有一个基本的问题,关于让webapp2 python服务器提供过大(约100 kb)的json数据作为Channel API消息发送的最简单方法客户。
webapp2服务器根据客户端请求在几分钟内生成多个数据文件,我想我希望Channel API在数据准备好时将带有url的消息发送到客户端,并且客户端(a GWT app)可以执行http GET请求来获取数据。每个数据文件对于客户端都是唯一的,因此服务器必须有一个请求处理程序,它将为客户端提供适当的数据文件。
在调用请求时,您是否可以编写一个请求处理程序,该处理程序可以直接从该特定客户端的另一个请求处理程序提供正确的数据文件?或者我是否需要先使用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)
答案 0 :(得分:1)
您可以将文件写入blobstore并从blobstore提供这些文件。
这是一个例子: https://developers.google.com/appengine/docs/python/blobstore/overview#Complete_Sample_App