5
5

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.

Railsで、S3にコンテンツをアップロードしCloudFrontから配信したメモ

Posted at

準備
1.S3にbacket作成
2.cloudfrontに新規distributionを作成し、originを1で作成したbacketにする

コントローラで必要な情報を指定(各パラメータはs3.ymlに設定した)
AWS.config( :access_key_id => S3_CONFIG['access_key_id'], :secret_access_key => S3_CONFIG['secret_access_key'])

対象のアクションに下記コードを書く
s3 = AWS::S3.new bucket = s3.buckets[S3_CONFIG['bucket']] file_name = file.original_filename file_full_path="users/images/#{@user.id}/#{file_name}" object = bucket.objects[file_full_path] object.write(file, :acl => :public_read)

下記のようなURLでアップロードされる
???.cloudfront.net/users/images/???/???

参考URL
http://joppot.info/2014/06/13/1583
http://akasata.com/articles/292
http://www.aguuu.com/archives/2012/12/paperclip/
http://rock-and-hack.blogspot.jp/2013/02/railsassetss3cloudfront.html

5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?