Question:
In aws-s3, there is a method (AWS::S3::S3Object.stream) that lets you stream a file on S3 to a local file. I have not been able to locate a similar method in aws-sdk.
i.e. in aws-s3, I do:
1 2 3 4 5 6 |
File.open(to_file, "wb") do |file| AWS::S3::S3Object.stream(key, region) do |chunk| file.write chunk end end |
The AWS::S3:S3Object.read method does take a block as a parameter, but doesn’t seem to do anything with it.
Answer:
The aws-sdk gem now supports chunked reads of objects in S3. The following example gives a demonstation:
1 2 3 4 5 6 7 |
s3 = AWS::S3.new File.open(to_file, "wb") do |file| s3.buckets['bucket-name'].objects['key'].read do |chunk| file.write chunk end end |