【问题标题】:GAE python: how to use delete_serving_urlGAE python:如何使用 delete_serving_url
【发布时间】:2016-08-15 11:12:01
【问题描述】:
  1. 首先我将图像存储:

    import cloudstorage as gcs 
    ... 
    path = '/bucket/folder/image.jpg'
    with gcs.open(path, 'w') as f:
        f.write(data)
    
  2. 然后我得到服务网址:

    url = images.get_serving_url(None, filename='/gs{}'.format(self.path),
                                 secure_url=True)
    

    服务 url 通常按预期工作,问题是我没有使用 blob_key,只有文件名(存储中的路径)。

  3. 我现在想知道如何删除serving_url,因为sdk方法只接受blob_key

    def delete_serving_url(blob_key, rpc=None):
        """Delete a serving url that was created for a blob_key using get_serving_url.
    
        Args:
        blob_key: BlobKey, BlobInfo, str, or unicode representation of BlobKey of
        blob that has an existing URL to delete.
        rpc: Optional UserRPC object.
    
        Raises:
          BlobKeyRequiredError: when no blobkey was specified.
          InvalidBlobKeyError: the blob_key supplied was invalid.
          Error: There was a generic error deleting the serving url.
        """
    

https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.images#google.appengine.api.images.delete_serving_url

【问题讨论】:

  • 所以delete_serving_url 删除 gcs 上的整个文件对吗?
  • 不,我删除了图片的 serving_url,所以它不能通过这个 url 访问

标签: google-app-engine gae-python27


【解决方案1】:

Using the Blobstore API with Google Cloud Storage 示例展示了如何为 GCS 获取等效的 blob_key:

blob_key = CreateFile(main.BUCKET + '/blobstore_serving_demo')

从那个链接:

注意:一旦您获得了 Google Cloud Storage 对象的 blobKey,您就可以将其传递、序列化或以其他方式使用它 可以在任何可以使用 blobKey 存储对象的地方互换 在 Blobstore 中。这允许在应用程序将一些数据存储在 blobstore 和一些在 Google Cloud Storage 中,但会处理数据 否则与应用程序的其余部分相同。 (但是,BlobInfo 对象不适用于 Google Cloud Storage 对象。)

所以您应该能够为您的文件生成一个 blobKey 并使用它调用 get_serving_urldelete_serving_url

您还可以使用 GCS 对象权限来阻止对文件的访问,请参阅 Setting object permissions and metadata

【讨论】:

  • 谢谢!听起来不错,我会试一试,然后接受答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-06
  • 2013-12-22
  • 1970-01-01
  • 2019-04-03
  • 1970-01-01
  • 2016-01-06
  • 1970-01-01
相关资源
最近更新 更多