Ruby和亚马逊S3如何打开文件,并进行身份验证? [英] Ruby and Amazon S3 how to open file and authenticate?

查看:188
本文介绍了Ruby和亚马逊S3如何打开文件,并进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打开Amazon 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?

我的助手

            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

我得到在查看错误:

I get the error in view:

uninitialized constant AWS::S3::Base

http://pastie.org/2587071

更新:

而不是宝石AWS-S3

它应该是:宝石AWS-S3',:要求=&GT; AWS / S3

推荐答案

你的问题如何写一个文件到S3?如果是这样,使用AWS-S3的宝石,你会做如下:

Is your question how to write a file to S3? If so, using the aws-s3 gem, you would do as follows:

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)

这篇关于Ruby和亚马逊S3如何打开文件,并进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆