![](/img/trans.png)
[英]Upload and retrieve files from Google Cloud Storage/ Buckets in Python/Django
[英]Google Cloud Storage streaming upload from Python generator
我有一個 Python 生成器,它將yield
大量未知數量的字節數據。 我想將 stream output 到 GCS,而不先緩沖到磁盤上的文件。
雖然我確信這是可能的(例如,我可以創建一個gsutil cp - <...>
的子進程並將我的字節寫入其標准輸入),但我不確定推薦/支持的方式和文檔給出上傳本地文件的例子。
我應該如何正確地做到這一點?
BlobWriter class 使這更容易一些:
bucket = storage_client.bucket('my_bucket')
blob = bucket.blob('my_object')
writer = BlobWriter(blob)
for d in your_generator:
writer.write(d)
writer.close()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.