gpt4 book ai didi

python - 从 Google AppEngine 中的 blobstore 下载 zip 存档

转载 作者:太空宇宙 更新时间:2023-11-03 19:20:56 25 4
gpt4 key购买 nike

我使用 python 开发 Google 应用引擎。我在 blobstore 中创建了 zip 存档,但当我尝试下载此文件时出现问题。

我将展示一些细节:首先,我在 blob 上创建了这个存档,然后我获得了这个上传文件的 key 。我想将 url 中的 key 发送到另一个 python 页面,如下所示:

print'<a href="download.py?key=%s">Save Zip</a>' % blob_key

现在在 download.py 页面中,我尝试从 url 获取 key ,如下所示:self.request.get('key'),但是不起作用。

在这个页面中我写了

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):

......等等

这是我用来下载 zip 的唯一类,但问题是我无法获取 key ,当我运行应用程序时,我遇到了这个问题:

****Status: 404 Not Found
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 0****

app.yaml代码:

application: cloudcomputingproject20122012
version: 1
runtime: python
api_version: 1

handlers:
- url: /compress.py
script: compress.py
- url: /decompress.py
script: decompress.py
- url: (.*)/
static_files: static\1/index.html
upload: static/index.html

现在在 compress.py 中我创建了两个类;创建 zip,将其存储在 blobstore 上,获取此存储文件的 bob 键,然后我将 blob 键定义为全局变量,现在在服务处理程序类中我尝试下载此 zip,但我不能。

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):

global x
#x="tvsD0KgYxX85hyC9wJHsqw=="
print x
x = str(urllib.unquote(x))
blob_info = blobstore.BlobInfo.get(x)
self.send_blob(blob_info,save_as=True)



def main():
application = webapp.WSGIApplication( [('/serve', ServeHandler),], debug=True)
c=zip()
c.z()
run_wsgi_app(application)

if __name__ == "__main__":
main()

最佳答案

App Engine 上的 Python 与 PHP 不同 - 请求 URL 不会直接映射到文件名;您不能指向 /download.php 并期望请求被路由到您的处理程序。您需要将处理程序映射到 URL,然后将请求指向该 URL;请参阅任何入门教程的示例。

关于python - 从 Google AppEngine 中的 blobstore 下载 zip 存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9778275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com