Ruby 和 Amazon S3 如何打开文件并进行身份验证?
如何在 Amazon S3 上打开文件并进行身份验证?
我知道如何使用回形针执行此操作,但是在必须打开文件时如何完成此操作?
我的助手
File.open("#{RAILS_ROOT}/public/xml/#{output}.xml", "w") do |f|
f.puts("<?xml version='1.0' encoding='UTF-8'?>")
f.puts("<site>")
f.puts("<general name='general' type='general'><imagePath>photographer/image/</imagePath><moviePath>../photographer/flv/</moviePath></general>")
f.puts("#{xmlmenu.to_xml}")
f.puts("#{xmlmovies.to_xml}")
f.puts("#{xmltextpages.to_xml}")
f.puts("</site>")
end
更新
My helper file:
module Admin::XmlHelper
require 'builder'
require 'aws/s3'
def update_xml(output)
AWS::S3::Base.establish_connection!(
:access_key_id => 'mykey',
:secret_access_key => 'mykey'
)
file = "xml/#{output}.xml"
content = "#{
f.puts("<?xml version='1.0' encoding='UTF-8'?>")
f.puts("<site>")
f.puts("<general name='general' type='general'><imagePath>photographer/image/</imagePath><moviePath>../photographer/flv/</moviePath></general>")
f.puts("#{xmlmenu.to_xml}")
f.puts("#{xmlmovies.to_xml}")
f.puts("#{xmltextpages.to_xml}")
f.puts("</site>")}"
AWS::S3::S3Object.store(file, content, "mybucket", :access => :public_read)
end
end
我在视图中收到错误:
uninitialized constant AWS::S3::Base
更新:
而不是 gem "aws-s3"
应该是:gem 'aws-s3', :require => 'aws/s3'
How do I open a file on Amazon S3 and authenticate?
I know how to do this with paperclip, but how is it done when having to open file?
My helper
File.open("#{RAILS_ROOT}/public/xml/#{output}.xml", "w") do |f|
f.puts("<?xml version='1.0' encoding='UTF-8'?>")
f.puts("<site>")
f.puts("<general name='general' type='general'><imagePath>photographer/image/</imagePath><moviePath>../photographer/flv/</moviePath></general>")
f.puts("#{xmlmenu.to_xml}")
f.puts("#{xmlmovies.to_xml}")
f.puts("#{xmltextpages.to_xml}")
f.puts("</site>")
end
UPDATE
My helper file:
module Admin::XmlHelper
require 'builder'
require 'aws/s3'
def update_xml(output)
AWS::S3::Base.establish_connection!(
:access_key_id => 'mykey',
:secret_access_key => 'mykey'
)
file = "xml/#{output}.xml"
content = "#{
f.puts("<?xml version='1.0' encoding='UTF-8'?>")
f.puts("<site>")
f.puts("<general name='general' type='general'><imagePath>photographer/image/</imagePath><moviePath>../photographer/flv/</moviePath></general>")
f.puts("#{xmlmenu.to_xml}")
f.puts("#{xmlmovies.to_xml}")
f.puts("#{xmltextpages.to_xml}")
f.puts("</site>")}"
AWS::S3::S3Object.store(file, content, "mybucket", :access => :public_read)
end
end
I get the error in view:
uninitialized constant AWS::S3::Base
Update:
Instead of gem "aws-s3"
Should it be: gem 'aws-s3', :require => 'aws/s3'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题是如何将文件写入S3?如果是这样,使用 aws-s3 gem,您将执行以下操作:
Is your question how to write a file to S3? If so, using the aws-s3 gem, you would do as follows:
为什么不使用 aws-s3 gem?
Why not use the aws-s3 gem?