编程语言
首页 > 编程语言> > python – 使用blobstore.create_gs_key创建的BlobKey中的BlobInfo对象

python – 使用blobstore.create_gs_key创建的BlobKey中的BlobInfo对象

作者:互联网

我正在从已弃用的文件api转换代码.

我有以下代码在SDK服务器中正常工作但在生产中失败.我正在做的甚至是正确的吗?如果是,那可能是什么问题,任何想法如何解决它?

# 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对象.

https://developers.google.com/appengine/docs/python/blobstore/#Python_Using_the_Blobstore_API_with_Google_Cloud_Storage

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.)

标签:blobstore,python,google-cloud-storage,google-app-engine
来源: https://codeday.me/bug/20190825/1719092.html