谷歌云存储谷歌应用引擎(Python)
问题描述:
谷歌云存储谷歌应用引擎(Python)使用任何代码示例?谷歌云存储谷歌应用引擎(Python)
迄今为止我见过的最好的是我从以前的问题,我发布收到答复:https://code.google.com/p/appengine-gcs-client/source/browse/trunk/python/demo/main.py
但是,代码似乎成功运行不管如何连接,我似乎无法找到我的GCS桶中的文件
答
main.py这个脚本直接上传到GCS,通过改变create_upload_url函数和删除gb_bucket_name它将使用blob存储。
import os
import urllib
import webapp2
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
class MainHandler(webapp2.RequestHandler):
def get(self):
upload_url = blobstore.create_upload_url('/upload', gs_bucket_name='bucket_name')
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.redirect('/serve/%s' % blob_info.key())
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
resource = str(urllib.unquote(resource))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
app = webapp2.WSGIApplication([('/', MainHandler),
('/upload', UploadHandler),
('/serve/([^/]+)?', ServeHandler)],
debug=True)
+0
刚试过这个,没有出现在GCS桶中。根据我看到的例子,似乎需要一些额外的配置,但不太确定。在下面的链接中运行示例代码,即使我摆脱了最终删除之后,该文件也不会显示在GCS控制台中...也不会完全上传:https://cloud.google .COM/AppEngine上/文档/蟒蛇/ Blob存储/#Python_Using_the_Blobstore_API_with_Google_Cloud_Storage – Dennis 2014-10-08 05:37:04
http://upload.gae-init.appspot.com/resource/upload/ – Lipis 2014-10-07 19:12:21