【发布时间】:2012-01-22 01:17:06
【问题描述】:
我将 blobstore 中的静态 KML 作为我保存到 blobstore 的文件提供
class KMLHandler2(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
resource = 'AMIfv965WtxAc_rWOVjSSx423_oe6f-g5obWYNKX5scg-1gqvISyaZCnv6lRaqro2wOVNOogttyMOylFLsRYZ3Y9UYIe-A69vAt4pdJB2-SHUcdVEM2v0XVLxzT3fTlxwXQVhzmsHPwALH_rCSFIvmYcuV37asVD0Q'
resource = str(urllib.unquote(resource))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
这可行,但我想定期更新文件。该文件是从/list.kml 生成的,所以我可以直接从那里读取它,但是它会超时,所以我的计划是让我的第一个appenine 任务从list.kml 读取文件并使用相同的密钥将其写入blobstore,但是当唯一的例子是如何创建一个新文件时,我该怎么做?我在代码中有更新数据层的地方,而且不是很频繁。你能建议我更新文件时应该怎么做吗?我想我希望密钥和 id 相同并替换旧的 blob,而不是编写新的并刷新密钥。你能帮助我吗?应用程序引擎文档说如何编写一个 blobstore 文件,但只是一个新文件,我不知道如何编辑或替换一个文件,因为它是关键,我认为这是我需要做的任务或 cron 工作所以我请求你的帮助。
我可以像文档中那样制作一个处理程序,但那是用于创建文件,而不是修改/替换文件:
class CreateKMLHandler(webapp2.RequestHandler):
def get(self):
# Create the file
file_name = files.blobstore.create(mime_type='application/octet-stream')
# Open the file and write to it
with files.open(file_name, 'a') as f:
f.write('data')
# Finalize the file. Do this before attempting to read it.
files.finalize(file_name)
# Get the file's blob key
blob_key = files.blobstore.get_blob_key(file_name)
谢谢
更新
我尝试使用此代码创建一个新文件,但它得到一个截止日期错误 applicationerror 5,我认为这是一个超时问题。我怎样才能让它成为一项任务?
class CreateKMLHandler(webapp2.RequestHandler):
def get(self):
# Create the file
file_name = files.blobstore.create(mime_type='application/octet-stream')
url = 'http://montaoproject.appspot.com/list.kml'
result = urlfetch.fetch(url)
if not result.content:
return
# Open the file and write to it
with files.open(file_name, 'a') as f:
f.write(result.content)
# Finalize the file. Do this before attempting to read it.
files.finalize(file_name)
# Get the file's blob key
blob_key = files.blobstore.get_blob_key(file_name)
self.out.write(blob_key)
【问题讨论】:
标签: python google-app-engine google-cloud-datastore kml python-2.7