First I put image to storage:
import cloudstorage as gcs ... path = '/bucket/folder/image.jpg' with gcs.open(path, 'w') as f: f.write(data)
Then I get serving url:
url = images.get_serving_url(None, filename='/gs{}'.format(self.path), secure_url=True)
Serving url generally works as expected, the thing is I'm not using blob_key, only filename (path in storage).
I wonder how to delete serving_url now, since sdk method only accepts 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. """
GAE python: how to use delete_serving_url
356 views Asked by glmvrml At
1
The Using the Blobstore API with Google Cloud Storage example shows how to obtain an equivalent blob_key for GCS:
From that link:
So you should be able to generate a blobKey for your file and call
get_serving_url
anddelete_serving_url
with it.You could also use GCS object premissions to prevent access to the file, see Setting object permissions and metadata.