2013-01-25 9 views
5

S3'de varolan veya yeni oluşturulan bir dosyaya nasıl metin eklenir. Ben fog kullanıyorum ve sonra S3 yüklenen kodRuby - Varolan s3 dosyasının sonundaki içeriği sisle ekleyin

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 

cevap

5

aşağıdakilere sahip bir dosya değişmez - değiştirilemez veya eklenen edilemez.

Yalnızca bir dosyaya toplu bir dosya yüklemek istiyorsanız, çoktan yükleme api'sini kullanabilirsiniz (10000 öğenin altında olduğunu varsayabilir ve sonuncusu en az 5 MB olacaktır). d muhtemelen sis talep seviyesine düşmeniz gerekir (şu andaki sis modellerini kullanmak yerine).

+0

Teşekkürler @Frederick Cheung. Çok fazla araştırma yaptıktan sonra aynı sonuca vardım. Bu arada, s3 url'un sis kullanarak nasıl imzalanacağını biliyor musun? Sis dokümantasyonunda bu konuyla ilgili herhangi bir bilgi bulunamadı. – JVK

İlgili konular