Created
April 10, 2013 15:45
-
-
Save shinofara/5355789 to your computer and use it in GitHub Desktop.
YAMLに設定を持たせて、rubyでS3へファイルUP ref: http://qiita.com/items/84c9fdefae40e9190005
This file contains hidden or 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
sudo gem i aws-s3 | |
vim /usr/local/lib/ruby/gems/2.0.0/gems/sauberia-aws-s3-0.6.2.1254423624/lib/aws/s3/extensions.rb |
This file contains hidden or 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
gsub!( Regexp.new("[\x80-\xFF]", Regexp::EXTENDED, 'n')) { "%02X" % $&[0] } |
This file contains hidden or 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
sudo ./sync_s3.rb |
This file contains hidden or 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
S3Object.store( | |
'test/test.html', # アップロード先のファイル名 | |
open(./test.html), # アップロードしたいローカルファイル | |
BUCKET_NAME, # バケット名 | |
:access => :public_read # 全体に読み込み公開(他にも認証必須とかあります) | |
); |
This file contains hidden or 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
#!/usr/local/bin/ruby | |
# -*- encoding: utf-8 -*- | |
# ディレクトリ以下取得 | |
require 'find' | |
require 'yaml' | |
require 'pp' | |
# s3 | |
# http://amazon.rubyforge.org/doc/ | |
require 'aws/s3' | |
include AWS::S3 | |
# 初期設定 | |
YAML_PATH = "./sync_s3.yml"; | |
data = YAML.load_file(YAML_PATH); # パースする | |
ACCESS_KEY_ID = data['main']['access_key_id']; | |
SECRET_ACCESS_KEY = data['main']['secret_access_key']; | |
BUCKET_NAME = data['main']['bucket_name']; | |
CURRENT_DIR = data['main']['current_dir']; | |
# S3設定 | |
Base.establish_connection!( | |
:access_key_id => ACCESS_KEY_ID, | |
:secret_access_key => SECRET_ACCESS_KEY, | |
:server => BUCKET_NAME + ".s3.amazonaws.com" # バケット名.s3.amazonaws.com | |
); | |
# S3への転送処理 | |
S3Object.store( | |
'test.html', # アップロード先のファイル名 | |
open(./test.html), # アップロードしたいローカルファイル | |
BUCKET_NAME, # バケット名 | |
:access => :public_read # 全体に読み込み公開(他にも認証必須とかあります) | |
); |
This file contains hidden or 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
main: | |
access_key_id : アクセスキー | |
secret_access_key : シークレットキー | |
bucket_name : backet名 | |
current_dir : /var/www/imgs/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment