2016-08-15 53 views
1
  1. 首先使用我把图像存储:GAE蟒蛇:如何delete_serving_url

    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) 
    

    投放网址通常按预期工作,东西是我没有使用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

+0

那么'delete_serving_url'删除gcs上的整个文件吧? –

+0

不,我删除serve_url图像,所以它不能通过此URL访问 – glmvrml

回答

2

Using the Blobstore API with Google Cloud Storage例子展示了如何获得用于GCS的等效blob_key:

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

从那个链接:

注:一旦你获得了谷歌云存储对象的blobKey,你可以到处传递它,序列化,否则使用它 互换任何地方,你可以使用一个的blobKey存储对象在Blobstore的 。这允许在应用程序将 Blobstore和一些数据存储在Google Cloud Storage中的某些数据的情况下使用,但是其他应用程序在其他情况下以相同方式处理数据 。 (然而,的BlobInfo 对象不适用于谷歌云存储的对象。)

所以,你应该能够产生的blobKey为您的文件并调用get_serving_urldelete_serving_url它。

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

+0

谢谢!听起来很稳定,我会试一试,然后接受答案 – glmvrml