Reputation: 157
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:
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.
Upvotes: 6
Views: 3431
Reputation: 6528
The aws-sdk gem now supports chunked reads of objects in S3. The following example gives a demonstation:
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
Upvotes: 6
Reputation: 13723
At this time, not officially. I found this thread in the official AWS Ruby forum:
Does the ruby aws gem support streaming download from S3. Quoting AWS staff:
Unfortunately there is not a good solution baked into the aws-sdk gem. We are looking into way we could make this much simpler for the end user.
There's sample code for downloading in chunks. You might want to have a look at that for inspiration.
Upvotes: 2