Created
January 30, 2013 23:10
-
-
Save gbaptista/4678203 to your computer and use it in GitHub Desktop.
Enviando arquivos para o Amazon S3 com Ruby.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# gem install aws-s3 | |
require 'aws/s3' | |
require 'stringio' | |
require 'fileutils' | |
# 10 anos = 60s x 60m x 31d x 12m x 10a | |
MAX_AGE = 60*60*31*12*10 | |
# Coloque o host de acordo com a zona do seu bucket | |
AWS::S3::DEFAULT_HOST.replace 's3-sa-east-1.amazonaws.com' | |
# Dados de acesso ao webservice | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => 'SUA TOKEN', | |
:secret_access_key => 'SUA SECRET' | |
) | |
# Enviando arquivo. | |
AWS::S3::S3Object.store( | |
'pasta1/pasta2/seu_arquivo.jpg', | |
StringIO.new(File.open('seu_arquivo.jpg', 'r').read), | |
'SEU BUCKET', | |
{ :'Cache-Control' => 'max-age=' + MAX_AGE.to_s, :access => :public_read } | |
) | |
# Criando arquivo | |
AWS::S3::S3Object.store( | |
'seu_arquivo.txt', | |
'conteudo do arquivo', | |
'SEU BUCKET', | |
{ :'Cache-Control' => 'max-age=' + MAX_AGE.to_s, :access => :public_read } | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment