How can I use boto to stream a file out of Amazon S3 to Rackspace Cloudfiles?

Other answers in this thread are related to boto, but S3.Object is not iterable anymore in boto3. So, the following DOES NOT WORK, it produces an TypeError: ‘s3.Object’ object is not iterable error message: s3 = boto3.session.Session(profile_name=my_profile).resource(‘s3’) s3_obj = s3.Object(bucket_name=my_bucket, key=my_key) with io.FileIO(‘sample.txt’, ‘w’) as file: for i in s3_obj: file.write(i) In boto3, the contents … Read more

Ruby on Rails 3: Streaming data through Rails to client

Assign to response_body an object that responds to #each: class Streamer def each 10_000_000.times do |i| yield “This is line #{i}\n” end end end self.response_body = Streamer.new If you are using 1.9.x or the Backports gem, you can write this more compactly using Enumerator.new: self.response_body = Enumerator.new do |y| 10_000_000.times do |i| y << “This … Read more