gpt4 book ai didi

python - 获取 Blobstore key

转载 作者:行者123 更新时间:2023-11-28 21:27:35 29 4
gpt4 key购买 nike

我正在阅读有关 Google App Engine 中的 Blobstore 的信息。下面的代码来自示例文档。用户选择要上传的文件并单击提交后,如何将 key 放入 javascript 变量中?我可以在页面上显示它,但我只想保留它以备后用。显然,我是 Web 编程的新手。

#!/usr/bin/env python
#

import os
import urllib
from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp.util import run_wsgi_app

class MainHandler(webapp.RequestHandler):
def get(self):
upload_url = blobstore.create_upload_url('/upload')
self.response.out.write('<html><body>')
self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % upload_url)
self.response.out.write("""Upload File: <input type="file" name="file"><br> <input type="submit"
name="submit" value="Submit"> </form></body></html>""")

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file') # 'file' is file upload field in the form
blob_info = upload_files[0]
self.response.out.write('<html><body>')
self.response.out.write(str(blob_info.key()))
self.response.out.write('</body><html>')

def main():
application = webapp.WSGIApplication(
[('/', MainHandler),
('/upload', UploadHandler),
], debug=True)
run_wsgi_app(application)

if __name__ == '__main__':
main()

最佳答案

你可以这样做:

self.response.out.write("""
<html>
<script>
var blobKey = "%s";
</script>
<body>
...
</body>
</html>""" % (blob_info.key(),)

关于python - 获取 Blobstore key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10727580/

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