簡體   English   中英

Ruby-使用fog將內容附加到現有s3文件的末尾

[英]Ruby - Append content at the end of the existing s3 file using fog

如何在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,並且除最后一個塊以外的所有塊都至少為5MB),但是您可能需要降到霧請求級別(而不是像現在那樣使用霧模型)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM