首页 文章

GAE python:如何使用delete_serving_url

提问于
浏览
2
  • 首先我把图像放到存储器中:
import cloudstorage as gcs 
... 
path = '/bucket/folder/image.jpg'
with gcs.open(path, 'w') as f:
    f.write(data)
  • 然后我得到服务网址:
url = images.get_serving_url(None, filename='/gs{}'.format(self.path),
                             secure_url=True)

服务网址通常按预期工作,事情是我不使用blob_key,只使用文件名(存储路径) .

  • 我想知道现在如何删除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

1 回答

  • 3

    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 端存储中时使用,但是应用程序的其余部分以相同的方式处理数据 . (但是,BlobInfo对象不适用于Google Cloud 端存储对象 . )

    因此,您应该能够为您的文件生成blobKey并使用它调用 get_serving_urldelete_serving_url .

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

相关问题