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.
在aws-s3中,有一个方法(AWS :: S3 :: S3Object.stream),它允许您将S3上的文件流式传输到本地文件。我无法在aws-sdk中找到类似的方法。
i.e. in aws-s3, I do:
即在aws-s3中,我这样做:
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.
AWS :: S3:S3Object.read方法确实将块作为参数,但似乎没有对它执行任何操作。
2 个解决方案
#1
5
The aws-sdk gem now supports chunked reads of objects in S3. The following example gives a demonstation:
aws-sdk gem现在支持S3中对象的分块读取。以下示例给出了演示:
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
#2
2
At this time, not officially. I found this thread in the official AWS Ruby forum:
这时候,不是正式的。我在官方AWS Ruby论坛中找到了这个帖子:
Does the ruby aws gem support streaming download from S3. Quoting AWS staff:
ruby是否支持来自S3的流式下载。引用AWS员工:
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.
不幸的是,aws-sdk gem没有很好的解决方案。我们正在研究如何让最终用户更加简单。
There's sample code for downloading in chunks. You might want to have a look at that for inspiration.
有用于下载块的示例代码。你可能想看看它的灵感。
#1
5
The aws-sdk gem now supports chunked reads of objects in S3. The following example gives a demonstation:
aws-sdk gem现在支持S3中对象的分块读取。以下示例给出了演示:
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
#2
2
At this time, not officially. I found this thread in the official AWS Ruby forum:
这时候,不是正式的。我在官方AWS Ruby论坛中找到了这个帖子:
Does the ruby aws gem support streaming download from S3. Quoting AWS staff:
ruby是否支持来自S3的流式下载。引用AWS员工:
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.
不幸的是,aws-sdk gem没有很好的解决方案。我们正在研究如何让最终用户更加简单。
There's sample code for downloading in chunks. You might want to have a look at that for inspiration.
有用于下载块的示例代码。你可能想看看它的灵感。