我是否需要在 Rails 应用程序中关闭与 Amazon S3 的连接?
我正在将 Rails 应用程序迁移到 Heroku,并且需要更改文件上传功能以使用 Amazon S3 而不是本地存储。我正在使用 aws-s3 gem 并且可以正常工作,但只是想确保我做的事情正确并且不会给自己带来问题。
在我的上传代码中,我有以下内容;
AWS::S3::Base.establish_connection!(
:access_key_id => 'Not telling',
:secret_access_key => 'Really not telling'
)
AWS::S3::S3Object.store("#{self.name}", upload_file_field.read, 'my_bucket')
这工作得很好,但我担心我会打开某种与服务器的连接。完成后我是否需要关闭连接(例如使用 AWS::S3::Base.disconnect
),或者我可以保持原样吗?
显然,我对与 S3 连接的幕后使用的协议不太了解,但我并不是特别想要 - 我只是想确保这能够正常工作而不会造成问题。
I'm migrating my rails app to Heroku and need to change my file upload functionality to use Amazon S3 instead of local storage. I am using the aws-s3 gem and have this working but just want to make sure that I'm doing things right and not creating problems for myself.
In my uploading code I have the following;
AWS::S3::Base.establish_connection!(
:access_key_id => 'Not telling',
:secret_access_key => 'Really not telling'
)
AWS::S3::S3Object.store("#{self.name}", upload_file_field.read, 'my_bucket')
This works perfectly but I'm concerned that I'm leaving some sort of connection to the server open. Do I need to close the connection once I'm done (e.g. with AWS::S3::Base.disconnect
) or can I just leave this as it is?
Clearly I don't have a good understanding of the protocols being used behind the scenes with my connection to S3 but I don't particularly want to - I just want to make sure that this will work without causing problems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请在此处查看 API 文档,特别是断开连接方法:
http://amazon.rubyforge.org/doc/classes/AWS/S3/Connection/Management/ClassMethods.html#M000088
目前尚不清楚是否必须显式关闭每个连接。但是,它确实提到如果打开持久连接会提高性能,无论如何默认情况下都会这样做。
Check here for the docs for the API, and the disconnect method in particular:
http://amazon.rubyforge.org/doc/classes/AWS/S3/Connection/Management/ClassMethods.html#M000088
It's not clear about whether you must close each connection explicitly. However, it does mention a performance increase if you open a persistent connection, this is done by default anyway.