Skip to main content
 首页 » 编程设计

python之将 GAE BlobInfo 转换为文件对象

2024年11月01日9luoye11

如何将 Google App Engine BlobInfo 对象转换为类文件对象以传递到 Google Cloud Storage?

请您参考如下方法:

我认为没有直接转换的机制。

您需要使用BlobReader 打开blob 并将其写入cloudstorage。

像这样:

blob_reader = BlobReader(blob_info.key()) 
data = blob_reader.read() 
filename = '/yourbucket/your_file_filename' 
with cloudstorage.open(filename, 'w') as f:  
    f.write(data) 

Cloudstorage 是 gcs client library

This question如果您需要迁移大量数据,可能会有所帮助。