简体   繁体   中英

Cannot upload files from S3 Development Bucket in Rails App

When running my rails app in development mode from Nitrous.io, I cannot access my development bucket which I set up on AWS S3. The upload button opens my personal computer, from where I don't want to load files. (even when I try to load files from my computer, I get a long error message stating "The request signature we calculated does not match the signature you provided. Check your key and signing method"

I think I don't have AWS S3 configured properly.

Currently, I have one IAM user, which I've assigned to AdministratorAccess Also, I am using the proper AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in my application.yml file. In fog.rb I have it read from the enviroment.

I should add too that I currently enrolled in a web development apprenticeship program.

Sorry for not showing my files

Here's my application.yml with the sensitive data taken out:

SENDGRID_PASSWORD: alphanumberic
SENDGRID_USERNAME: -------@heroku.com
AWS_ACCESS_KEY_ID: alphanumeric
AWS_SECRET_ACCESS_KEY: alphanumeric
development:
  AWS_BUCKET: vmanamino-bloccit-development
production:
  AWS_BUCKET: vmanamino-bloccit-production

development:
  secret_key_base: alphanumeric
test:
  secret_key_base: alphanumeric

Here's my fog.rb file which reads the values from the environment

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider:  'AWS',
    aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
    aws_secret_access_key: ENV['AWS_ACCESS_KEY_ID'],       
  }

  config.fog_directory = ENV['AWS_BUCKET']

  config.fog_public = true
end

您正在使用AWS_ACCESS_KEY_ID环境变量作为访问密钥和秘密访问密钥,而后者当然应该使用ENV['AWS_SECRET_ACCESS_KEY']

I didn't realize I needed to enclose the KEY ID and the SECRET KEY in quotes. Once I did that, I got it to work. I can upload images from my conputer to S3. Also, I didn't understand the assignment perfectly. I thought my app would upload images from S3. Now, the error raised earlier makes sense. I upload from my computer sending the image to S3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM