Skip to content

Instantly share code, notes, and snippets.

@bluerabbit
Created December 11, 2012 11:37
Show Gist options
  • Save bluerabbit/4257941 to your computer and use it in GitHub Desktop.
Save bluerabbit/4257941 to your computer and use it in GitHub Desktop.
fogを使ってS3にファイルをアップロードする
require 'rubygems'
require 'fog'
# https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key
YOUR_AWS_ACCESS_KEY_ID='your_key'
YOUR_AWS_SECRET_ACCESS_KEY='your_key'
connection = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => YOUR_AWS_ACCESS_KEY_ID,
:aws_secret_access_key => YOUR_AWS_SECRET_ACCESS_KEY,
:region => 'ap-northeast-1'
})
directory = connection.directories.create(
:key => "fog-demo",
:public => true
)
directory = connection.directories.get('fog-demo')
local_file = File.open("/path/your/file.txt")
s3_file = directory.files.create(
:key => local_file.to_path.split(File::SEPARATOR).last,
:body => local_file,
:public => true
)
@bluerabbit
Copy link
Author

fog document url
http://fog.io/1.8.0/storage/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment