S3.YML - 访问变量?基于当前环境?
我使用的回形针有一个 /config/s3.yml 文件,其中包含以下内容:
common: &common
access_key_id: XXXXXXXXXX
secret_access_key: XXXXXXXXXXXXXXXXXXXX
development:
<<: *common
bucket: myapp-local-dev
test:
<<: *common
bucket: myapp-123-test
production:
<<: *common
bucket: myappname-313-production
在我看来,我希望动态地能够执行如下操作:
<img src="http://s3.amazonaws.com/myapp-local-dev/1/photos/15/1/thumb/Logo%20Design%20by%20kuda-1.jpeg" />
或
<img src="http://s3.amazonaws.com/myappname-313-production/1/photos/15/1/thumb/Logo%20Design%20by%20kuda-1.jpeg" />
以某种方式了解当前环境,然后获取存储桶名称。可能的?谢谢
I'm using paperclip which has a /config/s3.yml file with the following:
common: &common
access_key_id: XXXXXXXXXX
secret_access_key: XXXXXXXXXXXXXXXXXXXX
development:
<<: *common
bucket: myapp-local-dev
test:
<<: *common
bucket: myapp-123-test
production:
<<: *common
bucket: myappname-313-production
In my view I would like to dynamically be able to do something like this:
<img src="http://s3.amazonaws.com/myapp-local-dev/1/photos/15/1/thumb/Logo%20Design%20by%20kuda-1.jpeg" />
or
<img src="http://s3.amazonaws.com/myappname-313-production/1/photos/15/1/thumb/Logo%20Design%20by%20kuda-1.jpeg" />
Somehow, knowing the current environment and then getting the bucket name. Possible? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
YAML.load_file("#{Rails.root}/config/s3.yml")[Rails.env]["bucket"]
如果您只想返回存储桶名称,应该可以解决问题。
如果您将 Paperclip 与 aws/s3 一起使用,这应该会自动处理。
所以:
<%= image_tag @my_obj.image.url %>
无论环境如何,都应该返回所需的 url
希望有帮助吗?
YAML.load_file("#{Rails.root}/config/s3.yml")[Rails.env]["bucket"]
Should do the trick if you just want to return the bucket name.
If you're using Paperclip with aws/s3 this should be handled automatically though.
So:
<%= image_tag @my_obj.image.url %>
should return the desired url regardless of the environment
Hope that helps?