python - 如何使用 Python 以追加模式打开 GCS 存储桶中的文件?

标签 python file google-cloud-platform google-cloud-storage

我查看了所有相关问题,我能找到的都是上传到 GCS 而不是写作。我不是要上传文件或创建新文件。我需要以附加模式打开位于谷歌云存储桶中的文件,即如果它不存在则创建它并使用 python 写入它的末尾。如果有人能指出我正确的方向,我将不胜感激。 上传方法每次都会替换我的文件。我试过下载、附加然后替换,但这需要文件最初存在于目录中。 有没有办法在 gcs 中实现追加模式功能?

PS:我正在尝试在云函数中执行此操作,而不是在配备 Cloud SDK 的机器上执行此操作

最佳答案

没有办法做到这一点,因为 GCS 中的对象是不可变的。

来自 https://cloud.google.com/storage/docs/key-terms#immutability :

Objects are immutable, which means that an uploaded object cannot change throughout its storage lifetime. An object's storage lifetime is the time between successful object creation (upload) and successful object deletion. In practice, this means that you cannot make incremental changes to objects, such as append operations or truncate operations. However, it is possible to overwrite objects that are stored in Cloud Storage, and doing so happens atomically — until the new upload completes the old version of the object will be served to readers, and after the upload completes the new version of the object will be served to readers. So a single overwrite operation simply marks the end of one immutable object's lifetime and the beginning of a new immutable object's lifetime.

关于python - 如何使用 Python 以追加模式打开 GCS 存储桶中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52715217/

相关文章:

C - 使用结构成员值的段错误

java - 如何更改此设置,使它无法实现我想要的方式?

node.js - 如何在云函数中的config.json文件中提及.csv和.json文件格式来触发DAG

networking - Kubernetes 更新更改了 Google Cloud 中节点的静态+保留的外部 IP

python - 如何在wx.Python中正确使用wx.CallLater

python - 稳健的 numpy.float64 相等性测试

python - 是我无法添加 ManyToManyField 的原因吗?

list - 在 forEach 循环中填充列表之前,我的异步调用正在返回

google-cloud-platform - 无法通过SSH/gcloud进入默认的Google深度学习虚拟机

python - 为 % 创建一个 Groupby Grand Total 行