python - python Firebase Cloud Storage - 上传文件而不将其保存在本地
问题描述
我想将 zip 文件上传到 Firebase Cloud Storage,但我想避免将其保存在本地。相反,我想将其存储在内存中(使用BytesIO
),然后直接上传。可能吗?
解决方案
Theoretically this should be possible to write from BytesIO
to storage without writing the file locally.
There is a method in Blob
class called upload_from_string
(reference). The method accepts bytes
and it's possible to add content type as well. Ex. I was able to run something like that:
# create simplest BytesIO object
b = io.BytesIO(b'hello')
# create storage client
storage_client = storage.Client()
# create test bucket
bucket = storage_client.bucket("vittoh-test-bytesio")
# create test blob
blob = bucket.blob("vitooh-test-blob")
# upload with type zip
blob.upload_from_string(b.read(),content_type='application/zip')
This created object with content_type "application/zip" in my testing bucket. I don't know how do you want to create this zip file in BytesIO
, but after that it should be possible.
推荐阅读
- angular - 如何在 ngOninit 中使用事件发射器调用共享服务?
- ruby-on-rails - Ruby on Rails 主页
- angular - Angular 文档站点根据访问者的不同操作系统切换版本?
- react-native - 更新由 RCTView 管理的视图的属性“转换”时出错
- java - 从哪里获取 JDK 7u131 补丁
- powershell - 如果来自另一个文件的引用正确,则将数据相加
- java - 在java中使用simpledateformat添加n天
- c# - 如何在应用程序配置文件中定义和加密连接字符串
- javascript - Web 应用程序关闭浏览器消息
- email - 为什么所有邮箱都在 Dynamics CRM 365 (on-prem) 中接收电子邮件?