来自使用 blobstore.create_gs_key 创建的 BlobKey 的 BlobInfo 对象
问题描述
我正在将代码从已弃用的文件 api 中转换出来.
I am converting code away from the deprecated files api.
我有以下代码在 SDK 服务器中运行良好,但在生产中失败.我在做什么甚至正确吗?如果是,可能出了什么问题,有什么解决方法的想法吗?
I have the following code that works fine in the SDK server but fails in production. Is what I am doing even correct? If yes what could be wrong, any ideas how to troubleshoot it?
# Code earlier writes the file bs_file_name. This works fine because I can see the file
# in the Cloud Console.
bk = blobstore.create_gs_key( "/gs" + bs_file_name)
assert(bk)
if not isinstance(bk,blobstore.BlobKey):
bk = blobstore.BlobKey(bk)
assert isinstance(bk,blobstore.BlobKey)
# next line fails here in production only
assert(blobstore.get(bk)) # <----------- blobstore.get(bk) returns None
解决方案
很遗憾,根据文档,您无法获取 GCS 文件的 BlobInfo 对象.
Unfortunately, as per the documentation, you can't get a BlobInfo object for GCS files.
https://developers.google.com/appengine/docs/python/blobstore/#Python_Using_the_Blobstore_API_with_Google_Cloud_Storage
注意:获得 GCS 对象的 blobKey 后,您可以传递它、序列化它,或者在任何可以对存储在 Blobstore 中的对象使用 blobKey 的地方互换使用它.这允许在应用程序将一些数据存储在 blobstore 中并将一些数据存储在 GCS 中的情况下使用,但应用程序的其余部分以相同的方式处理数据.(但是,BlobInfo 对象目前不可用于 GCS 对象.)
Note: Once you obtain a blobKey for the GCS 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 GCS, but treats the data otherwise identically by the rest of the app. (However, BlobInfo objects are currently not available for GCS objects.)
相关文章