Currently, I am creating an image posting site like intagram.
I was able to save the image with activestorage and display the image locally.
I was implementing to save images using AWS S3
I got an error if I couldn't save the posted image.
Aws :: Sigv4 :: Errors :: MissingCredentialsError in ItemsController # create
Cannot load `Rails.config.active_storage.service`: missing credentials, provide credentials with one of the following options:-: access_key_id and: secret_access_key-: credentials-: credentials_provider
Corresponding source code
def create
Item.create (item_params)
# Save item model
Specify what is quoted in item_params with # praivate
@ item.image.attach (params [: image])
end
private
def item_params
params.require (: item) .permit (: text,: image) .merge (user_id: current_user.id)
#Allow only item names and photos
What is the #merge method? Combine two hashes into one
end
What I tried
def create
Item.create (item_params)
Add code here ➡︎@item.image.attach (params [: image])
end
NoMethodError occurs even before writing the code of ➡︎
Supplementary information (FW/tool version, etc.)config/environment/development.rb
config.active_storage.service =: amazon
config/envilorments/production.rb
config.active_storage.service =: amazon
➡︎ Change save destination from local to amazon
config/storage.yml
amazon:
service: S3
access_key_id: "<% = ENV ['AWS_ACCESS_KEY_ID']%>"
secret_access_key: "<% = ENV ['AWS_SECRET_ACCESS_KEY']%>"
region: ap-northeast-1
bucket: nostalgia2020
Environment variables in the terminal
vim ~/.zshrc
source ~/.zshrc
source ~/.bash_profile
I implemented and arranged the above.
-
Answer # 1
Related articles
- ruby on rails - image cannot be saved (activestorage installed) null in image of table
- ruby on rails - data cannot be saved in the intermediate table (parameters cannot be passed)
- ruby on rails - saved description in nested controller
- ruby on rails 5 - actioncontroller :: invalidauthenticitytoken cannot be resolved
- ruby - [rails] i want to create an image link using the url of the image output using active storage
- ruby on rails - about matters that cannot be migrated
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby on rails - s3 images are not saved on the ec2 server
- ruby on rails - webpacker cannot be compiled
- ruby - cannot be saved due to validation of the mating table of the intermediate table
- ruby on rails - creating an image posting application where the data entered in the form is not saved
- ruby on rails - rails associated model is not saved in db
- ruby on rails - about image distribution on heroku and s3
- ruby on rails - it is not saved in the database after registering the product
- ruby on rails - vuejs cannot find element: app error
- ruby on rails - i want to display the posted image in the background using image_tag or url_for
- rails background image cannot be displayed scss
- ruby on rails - you cannot change the keychain after downloading the pem file when creating an ec2 instance the matter that come
- ruby on rails 5 - rails cannot retrieve params data
- ruby on rails - rails tutorial chapter 13 cooperation between heroku and aws s3 region
- ruby on rails - about image distribution on heroku and s3
- windows - rails tutorial chapter 13 (1344) image upload in production environment does not work (s3, iam)
- ruby - resource: the server responded with a status of 404 () error
- ruby - aws deployment the asset "" is not present in the asset pipeline cannot be resolved
- ruby on rails - s3 images are not saved on the ec2 server
- ruby on rails - i implemented it so that images can be saved in s3 of aws, but the view can no longer be displayed
- ruby - how to upload images directly from rails to s3 on aws
- nginx - bundler: failed to load command: unicorn cannot start with an error saying unicorn_rails
access_key_id: "<% = ENV ['AWS_ACCESS_KEY_ID']%>"
secret_access_key: "<% = ENV ['AWS_SECRET_ACCESS_KEY']%>"
Delete unnecessary items with "" above.
Run vim ~/.zshrc in terminal
export AWS_SECRET_ACCESS_KEY =
Where you have to
AWS_SECRET_ACCESS_KEYS =
It had become.
Once when I was running vim ~/.zshrc
I don't know how to use it when I accidentally delete it
It was because I had deleted it.