gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 04:30:33 24 4
gpt4 key购买 nike

我查看了所有相关问题,我能找到的都是上传到 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com