python - 说明 - 使用 Blobstore API 将图像/视频上传到 Google Cloud Storage

标签 python google-app-engine google-cloud-storage blobstore google-console-developer

我一直在绞尽脑汁地试图弄清楚如何使用 Blobstore API 将图像/视频上传到我的 App Engine Python Web 应用程序的 Google 云存储。这是我目前所处的位置:

我使用以下代码为 HTML 表单创建操作 URL。

upload_url = create_upload_url('/upload', gs_bucket_name='bucket')

我使用 webapp2/Jinja 模板并将 upload_url 传递到我的 HTML 模板中。

<form action="{{upload_url}}" method="POST" enctype="multipart/form-data">
   <input type="file" name="file">
   <input type="submit" name="submit" value="SUBMIT">
</form>

我知道这会将文件直接上传到 Google Cloud Storage,然后使用 blob 键调用我的 /upload 处理程序。

我很困惑之后该做什么。这是我的 /upload 处理程序代码:

 class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        upload = self.get_upload()[0]
        blob_key = upload.key()

这是在将图像/视频上传到 Google Cloud Storage 时获取 blob_key 的正确方法吗?

文档说使用 blobstore.create_gs_key('/gs' + 'bucketname' + 'filename') 创建 blob_key。文件名从何而来?这段代码是否应该进入我的上传处理程序的 post 函数,该处理程序在对象存储在 GCS 中后调用?

另外,从 Google 文档来看,我对这段代码的作用或适合图片的内容感到困惑:

with gcs.open(filename, 'w') as f:
f.write('abcde\n')

最佳答案

查看我刚刚在 GitHub 中为您创建的示例:

https://github.com/lucena/gae-upload-gcs

如果您对此有任何疑问,请告诉我。

关于python - 说明 - 使用 Blobstore API 将图像/视频上传到 Google Cloud Storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35975541/

相关文章:

python - 如何判断返回的光标是否是 App Engine 中的最后一个光标

google-app-engine - 如何在 Google App Engine 中执行全文搜索?

python - GAE GCS write 是否像 NDB 函数一样具有异步版本

python - 将字典键指定为数据框名称,将值指定为数据框本身

python - 根据分隔符垂直拆分 DataFrame

python - 将 python 与 os.fork 一起使用

java - 如何将图像从 Android 上传到 Google Cloud (Java)?

go - 在 Google Cloud Platform 中使用 Buckets 和 Golang

google-cloud-platform - 如何从我的 Google Developers Console 识别 Google Cloud Storage URI?

python - 如何打印 EXCEL 格式的报告 (XLS)