【问题标题】:Ruby - Append content at the end of the existing s3 file using fogRuby - 使用雾在现有 s3 文件的末尾附加内容
【发布时间】:2013-01-25 00:55:30
【问题描述】:

如何在 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

【问题讨论】:

    标签: ruby amazon-s3 fog


    【解决方案1】:

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

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

    【讨论】:

    • 感谢@Frederick Cheung。经过这么多的研究,我得出了同样的结论。顺便说一句,您知道如何使用雾对 s3 url 进行签名吗?在雾文档中找不到任何关于它的信息。
    猜你喜欢
    • 1970-01-01
    • 2012-06-21
    • 2016-11-10
    • 2018-03-01
    • 2014-02-24
    • 2021-03-16
    • 1970-01-01
    • 2021-09-07
    • 2017-06-15
    相关资源
    最近更新 更多