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

관련 문제