GAE python:如何使用delete_serving_url [英] GAE python: how to use delete_serving_url
问题描述
将cloudstorage导入为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)
服务URL一般按预期工作,事情是我没有使用blob_key,只有filename(存储路径)。
我想知道现在如何删除serving_url,因为sdk方法只接受blob_key
def delete_serving_url(blob_key,rpc = None):
使用get_serving_url删除为blob_key创建的服务网址
$ b参数:
blob_key:BlobKey ,BlobInfo,str或BlobKey的unicode表示,
blob具有要删除的现有URL
rpc:可选的UserRPC对象。
提高:
BlobKeyRequiredError:未指定blobkey时。
InvalidBlobKeyError:提供的blob_key无效。
错误:删除服务网址时出现一般性错误。
将Blobstore API与Google云端存储配合使用示例显示了如何为GCS获取等效的blob_key:
pre $ blob_key = CreateFile(main.BUCKET +'/ blobstore_serving_demo ')
从该链接:
注意:为Google云端存储对象获取 blobKey 后,您可以将它传递出去,将其序列化,否则将u您可以在任何地方使用 blobKey 作为存储
的对象在Blobstore中交换
。这允许应用程序将应用程序在
blobstore和一些在Google Cloud Storage中存储一些数据的应用程序中使用,但在应用程序的其余部分以相同方式处理数据
。 (但是, BlobInfo
对象不适用于Google Cloud Storage对象。)
您应该可以为您的文件生成一个blobKey,并使用它调用 get_serving_url
和 delete_serving_url
。
您也可以使用GCS对象权限来阻止访问该文件,请参阅设置对象权限和元数据。
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. """
The Using the Blobstore API with Google Cloud Storage example shows how to obtain an equivalent blob_key for GCS:
blob_key = CreateFile(main.BUCKET + '/blobstore_serving_demo')
From that link:
Note: Once you obtain a blobKey for the Google Cloud Storage object, you can pass it around, serialize it, and otherwise use it interchangeably anywhere you can use a blobKey for objects stored in Blobstore. This allows for usage where an app stores some data in blobstore and some in Google Cloud Storage, but treats the data otherwise identically by the rest of the app. (However, BlobInfo objects are not available for Google Cloud Storage objects.)
So you should be able to generate a blobKey for your file and call get_serving_url
and delete_serving_url
with it.
You could also use GCS object premissions to prevent access to the file, see Setting object permissions and metadata.
这篇关于GAE python:如何使用delete_serving_url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!