4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby(aws-sdk)から、S3にファイルをアップロードする

Last updated at Posted at 2015-05-11

aws-cli でやろうとすると、 Python をインストール(しかも2.6.3以降とか求められたりする…)する → pip(Pythonのパッケージ管理ツール)をインストールする → pip install awscli と手順を踏まなければならず、なかなか面倒だったりするので…

Ruby+gem installなら、ワンステップでinstallが終わる(Ruby+gemが入ってる前提だけど…)ので、こちらの方が手早い場合が多い。(Rubyist的には)

$ gem install aws-sdk
$ irb -r 'aws-sdk'
bucket_name = 'my-bucket'
s3_path = 's3-path/to'
upload_file_path = 'path/to'
file_name = 'file'

AWS.config(
  :access_key_id => 'YOUR_ACCESS_KEY_ID',
  :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')

s3 = AWS::S3.new
bucket = s3.buckets[bucket_name]
o = bucket.objects[s3_path + '/' + file_name]

o.write(file: upload_file_path + '/' + file_name)

必要な場所を適当書き換えてネ。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?