使用文件服务URL从Blobstore中删除文件

使用文件服务URL从Blobstore中删除文件

问题描述:

在我的应用程序(GAE上的GWT)中,我们将存储在blobstore上的服务URL存储在我们的数据库中。当用户选择其中一个文件并点击删除时,我们需要从blobstore中删除文件。

In my app (GWT on GAE) we are storing on our database the serving URL that is stored on blobstore. When user selects one of these files and clicks "delete", we need to delete the file from blobstore.

这是我们的代码,但它不会删除文件all:

This is our code, but it is not deleting the file at all:

public void remove(String fileURL)
{
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
    String key = getBlobKeyFromURL(fileURL);
    BlobKey blobKey = new BlobKey(key);
    blobstoreService.delete(blobKey);
}

其中 fileURL 的样子像这样:

http://lh6.ggpht.com/d5VC0ywISACeJRiC3zkzaZug-tPsaI_LGt93-e_ATGTCwnGLao4yTWjLVppQ

并且 getBlobKeyFromURL()会返回最后一个/之后的内容,in这个例子:

And getBlobKeyFromURL() would return what is after the last "/", in this example:

d5VC0ywISACeJRiC3zkzaZug-tPsaI_LGt93-e_ATGTCwnGLao4yTWjLVppQ

* 编辑: * 似乎getBlobKeyFromURL()返回的不是blobKey。 blobKey是一个不同的字符串,在 / download?blob-key = 之前,返回 fileURL 。所以现在的问题是:我如何从URL获取blobKey?

** Seems that what getBlobKeyFromURL() returns is not the blobKey. The blobKey is a different string that, with /download?blob-key= before, returns the fileURL. So the question now would be: how can I get the blobKey from the URL?

您能否请教?

感谢

Thanks

无法从服务网址派生原始blobkey。如果这是你想要做的事情,那么我建议你在生成URL时在数据存储中存储URL - > BlobKey映射。

There is no way to derive the original blobkey from the serving URL. If this is something you want to do, then I suggest storing the URL -> BlobKey mapping in the datastore when you generate the URL.