質問編集履歴
1
タイトル、内容の変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
carrierwaveを用いて画像をs3にアップしようとしたら、
|
1
|
+
carrierwaveを用いて画像をs3にアップしようとしたら、Missing required arguments: aws_access_key_id, aws_secret_accessとなった
|
body
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
##実現したいこと
|
2
|
+
|
3
|
+
作成しているブログアプリに画像アップ機能を搭載しようとしています。
|
4
|
+
初期段階として、画像をアップする機能は開発、本番環境共に作れたのですが、s3に保存をしようとしてもできなくなりました。
|
5
|
+
|
2
6
|
[【AWS】ローカル環境の画像保存先をS3に変更する方法を1から解説](https://techtechmedia.com/local-s3-aws/)を参考にまずは開発環境で画像の保存先をs3に変更したいと考えています。
|
3
7
|
|
4
8
|
|
9
|
+
|
5
10
|
##エラー
|
6
|
-
|
11
|
+
localhost:3000などアプリケーションの大半のページは問題なく動作するのですが、記事投稿画面で投稿の送信をしようとすると下記のエラーが発生します。
|
7
12
|
|
8
13
|
```chrome
|
9
|
-
|
14
|
+
ArgumentError in PostsController#create
|
10
15
|
|
11
|
-
|
16
|
+
Missing required arguments: aws_access_key_id, aws_secret_access_key
|
12
17
|
```
|
13
18
|
|
14
|
-
##な
|
19
|
+
##原因になってそうな?コード
|
15
20
|
|
16
21
|
```PostsController
|
17
22
|
def create
|
@@ -72,18 +77,54 @@
|
|
72
77
|
|
73
78
|
```ImageUploader
|
74
79
|
class ImageUploader < CarrierWave::Uploader::Base
|
75
|
-
# Include RMagick or MiniMagick support:
|
76
|
-
|
80
|
+
if Rails.env.development?
|
81
|
+
storage :fog
|
77
|
-
|
82
|
+
elsif Rails.env.test?
|
83
|
+
storage :file
|
84
|
+
else
|
85
|
+
storage :fog
|
86
|
+
end
|
78
87
|
|
79
|
-
process resize_to_fit: [500, 300]
|
80
|
-
|
81
88
|
def store_dir
|
82
89
|
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
83
90
|
end
|
91
|
+
|
92
|
+
def extension_whitelist
|
93
|
+
%w(png jpg)
|
94
|
+
end
|
95
|
+
|
96
|
+
def filename
|
97
|
+
original_filename if original_filename
|
98
|
+
end
|
84
99
|
end
|
100
|
+
```
|
85
101
|
|
102
|
+
```secrets
|
103
|
+
# Be sure to restart your server when you modify this file.
|
86
104
|
|
105
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
106
|
+
# If you change this key, all old signed cookies will become invalid!
|
107
|
+
|
108
|
+
# Make sure the secret is at least 30 characters and all random,
|
109
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
110
|
+
# You can use `rails secret` to generate a secure secret key.
|
111
|
+
|
112
|
+
# Make sure the secrets in this file are kept private
|
113
|
+
# if you're sharing your code publicly.
|
114
|
+
|
115
|
+
development:
|
116
|
+
secret_key_base: 文字列・・・・・
|
117
|
+
aws_access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
|
118
|
+
aws_secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
|
119
|
+
|
120
|
+
test:
|
121
|
+
secret_key_base: 文字列・・・・・
|
122
|
+
|
123
|
+
# Do not keep production secrets in the repository,
|
124
|
+
# instead read values from the environment.
|
125
|
+
production:
|
126
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
127
|
+
|
87
128
|
```
|
88
129
|
|
89
130
|
また、gemfileにはgem 'carrierwave'とgem 'fog-aws'を記述の上でbundle installも行っています。
|