簡體   English   中英

Ruby和Amazon S3如何打開文件並進行身份驗證?

[英]Ruby and Amazon S3 how to open file and authenticate?

如何在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

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-s3 gem?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM