问题描述
我目前正在开发,试图复制/从一个桶移动视频到另一个S3 Rails应用程序。但是我一直在我的Rails应用程序获得的代理错误502。在杂种登录它说:无法分配内存。一旦发生这种错误的应用程序死了,我们必须重新启动的。
I am currently developing a rails application that tries to copy/move videos from one bucket to another in s3. However i keep getting a proxy error 502 on my rails application. In the mongrel log it says "failed to allocate memory." Once this error occurs the application dies and we must restart is.
推荐答案
好像你的code是阅读整个资源到内存中,并-的,回忆了您的应用程序。一个天真的方式做到这一点(和你的描述,你在做这样的事情的话)将要下载的文件,并再次上传:只需将其下载到本地文件,而不是到内存中。然而,亚马逊的工程师们认为尽管提供的API,可以用这个特例处理,也是如此。
Seems like your code is reading the entire resource into memory, and that out-of-memories your application. A naïve way to do this (and from your description, you're doing something like this already) would be to download the file and upload it again: just download it to a local file and not into memory. However, Amazon engineers have thought ahead and provide APIs that can deal with this specific case, as well.
如果你正在使用类似的RightAWS宝石,你可以使用它的S3Interface像这样:
If you're using something like the RightAWS gem, you can use its S3Interface like so:
# With s3 being an S3 object acquired via S3Interface.new
# Copies key1 from bucket b1 to key1_copy in bucket b2:
s3.copy('b1', 'key1', 'b2', 'key1_copy')
如果您使用的是赤裸裸的S3 HTTP接口,见亚马逊的对象复制文档为只使用HTTP从一个桶复制一个对象到另一个解决方案。
And if you're using the naked S3 HTTP interface, see amazon's object copy docs for a solution that uses only HTTP to copy one object from one bucket to another.
这篇关于如何复制使用S3从Rails应用程序水桶之间的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!