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?
- 301 S3上传后永久移动
- Ruby on Rails / Paperclip / AWS :: S3 :: NoSuchBucket错误
- Seahorse :: Client :: NetworkingError使用rails上传Amazon S3文件
- 建议在Ruby中为S3 Bucket生成预签名URL的方法
- 有没有办法在推送到heroku时将资产管道资产资产转到s3?
- 密钥就在那里,但我仍然得到`fetch’:找不到密钥:“S3_BUCKET_NAME”(KeyError)
- “拒绝访问” – 用户对S3 Bucket的权限
- 列出存储桶时,Ruby Amazon S3 Access被拒绝
- 回形针可以从S3铲斗中读取照片几何图形吗?