2013-01-25 5 views
5

S3の既存のファイルまたは新しく作成されたファイルにテキストを追加する方法。私はfogを使用していますが、私は一度S3にアップロードされたコードRuby - 霧を使って既存のs3ファイルの最後にコンテンツを追加

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 

答えて

5

次き、ファイルは不変である - それは変更またはに追加することはできません。

ファイルをチャンクでアップロードするだけの場合は、マルチパートアップロードAPIを使用することができます(10000チャンク以下で、最後のものは5MB以上と仮定します)おそらく、現在のように霧モデルを使用する代わりに、霧の要求レベルに落とす必要があります。

+0

ありがとう@Frederick Cheung。私は多くの研究をした後、同じ結論に達しました。ところで、あなたは霧を使ってs3のURLに署名する方法を知っていますか?霧の文書でそれに関する情報を簡単に見つけることができませんでした。 – JVK

関連する問題