blobstore "Create_upload_url" 的 GCS 等价物是什么?

What is the GCS equivalent of the blobstore "Create_upload_url"?

我们目前使用 blobstore.create_upload_url 创建要在前端使用的上传 URL,请参阅 Uploading a blob。 但是,随着 Google 对云存储 (GCS) 的推动 Google,我想使用 GCS 而不是 blobstore。我们目前使用 blobstore.create_upload_url 但我在 GCS 文档中找不到任何等效内容。我错过了什么吗?有没有更好的方式从前端上传文件到GCS?

谢谢 罗布

如果您将 gs_bucket_name 提供给 blobstore.create_upload_url 文件将存储在 GCS 而不是 blobstore 中,这在官方文档中有描述:Using the Blobstore API with Google Cloud Storage

blobstore.create_upload_url(
                success_path=webapp2.uri_for('upload'),
                gs_bucket_name="mybucket/dest/location")

您可以看一下在 webapp2 中实现的简单上传处理程序

from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
import webapp2
import cloudstorage as gcs


class Upload(blobstore_handlers.BlobstoreUploadHandler):
    """Upload handler
    To upload new file you need to follow those steps:

    1. send GET request to /upload to retrieve upload session URL
    2. send POST request to URL retrieved in step 1
    """
    def post(self):
        """Copy uploaded files to provided bucket destination"""
        fileinfo = self.get_file_infos()[0]
        uploadpath = fileinfo.gs_object_name[3:]
        stat = gcs.stat(uploadpath)

        # remove auto generated filename from upload path 
        destpath = "/".join(stat.filename.split("/")[:-1])

        # copy file to desired location with proper filename 
        gcs.copy2(uploadpath, destpath)
        # remove file from uploadpath
        gcs.delete(uploadpath)

    def get(self):
        """Returns URL to open upload session"""

        self.response.write(blobstore.create_upload_url(
            success_path=uri_for('upload'),
            gs_bucket_name="mybucket/subdir/subdir2/filename.ext"))