Ruby和Amazon S3如何打开文件并进行身份validation?

如何在Amazon S3上打开文件并进行身份validation?

我知道如何用回形针做到这一点,但是如何打开文件呢?

我的帮手

File.open("#{RAILS_ROOT}/public/xml/#{output}.xml", "w") do |f| f.puts("") f.puts("") f.puts("photographer/image/../photographer/flv/") f.puts("#{xmlmenu.to_xml}") f.puts("#{xmlmovies.to_xml}") f.puts("#{xmltextpages.to_xml}") f.puts("") 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("") f.puts("") f.puts("photographer/image/../photographer/flv/") f.puts("#{xmlmenu.to_xml}") f.puts("#{xmlmovies.to_xml}") f.puts("#{xmltextpages.to_xml}") f.puts("")}" AWS::S3::S3Object.store(file, content, "mybucket", :access => :public_read) end end 

我在视图中收到错误:

 uninitialized constant AWS::S3::Base 

http://pastie.org/2587071

更新:

而不是gem "aws-s3"

应该是: gem 'aws-s3', :require => 'aws/s3'

您的问题是如何将文件写入S3? 如果是这样,使用aws-s3 gem,您将执行以下操作:

 AWS::S3::Base.establish_connection!( :access_key_id => MY_ACCESS_KEY, :secret_access_key => MY_SECRET_ACCESS_KEY ) content = "this is the content"; AWS::S3::S3Object.store("any_file_name.html", content, "my_bucket_name", :access => :public_read) 

为什么不使用aws-s3gem?