Ruby – 使用雾在现有s3文件的末尾附加内容
发布时间:2020-12-17 03:15:43 所属栏目:百科 来源:网络整理
导读:如何在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 = conn
如何在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 解决方法
上传到S3后,文件是不可变的 – 无法更改或追加.
如果你只是想要以块的形式上传文件,你可以使用multipart上传api,(假设你有10000块以下,除了最后一块将至少5MB),但是你可能需要降至雾化请求级别(而不是像当前那样使用雾模型). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |