gpt4 book ai didi

Ruby - 使用 fog 在现有 s3 文件的末尾追加内容

转载 作者:数据小太阳 更新时间:2023-10-29 07:16:13 24 4
gpt4 key购买 nike

如何在 S3 中的现有文件或新创建的文件中附加文本。我正在使用 fog 并且我有以下代码

require 'fog'
file = "abc.csv"
bucket = 'my_bucket'
storage = Fog::Storage.new(:provider => 'AWS', :aws_access_key_id => 'XXXXXXXX', :aws_secret_access_key => 'YYYYYYYY')
dir = connection.directories.new(:key => bucket) # no harm, if this bucket already exists, if not create one
buffer = ["big_chunk1", "big_chunk2", "big_chunk3", "big_chunk4", "big_chunk5"]

# I need help after this line. No changes above.
buffer.each do |chunk|
# this will not work as it will not append text below the existing file or
# newly created one. I am not looking for solution suggesting, buffer.join('')
# and then write whole chunk at once. I have to write in chuck for some specific reason.
# Also I dont want to first read existing data and then take in to memory
# and then append and finally write back.
dir.files.create(:key => file, :body => chunk, :public => false)
end

最佳答案

一旦上传到 S3,文件就是不可变的 - 它无法更改或附加。

如果您只是想分块上传文件,您可以使用分段上传 api,(假设您有不到 10000 个 block 并且除最后一个以外的所有 block 至少为 5MB),但是您会可能需要降低到雾请求级别(而不是像当前那样使用雾模型)。

关于Ruby - 使用 fog 在现有 s3 文件的末尾追加内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14513629/

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