简体   繁体   English

Amazon S3-载波图像上传

[英]Amazon S3 - Carrierwave Image Upload

So, I'm trying to upload an image from the Rails API to S3, using Fog. 因此,我正在尝试使用Fog将图像从Rails API上传到S3。

Whenever I try to upload the image, I get this: 每当我尝试上传图像时,都会得到以下信息:

  Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden)
  (...)
  All access to this object has been disabled

It is working in development, but once I switch to production, I receive the error above. 它正在开发中,但是一旦我投入生产,就会收到上述错误。 I'm using the keys from an user I've created that set full administrative permissions to. 我使用的是我创建的用户的密钥,该密钥设置了完整的管理权限。

My carrierwave.rb: require 'carrierwave' 我的carrierwave.rb:需要'carrierwave'

CarrierWave.configure do |config|

  config.fog_credentials = {
    :provider               => "AWS",
    :region                 => "us-east-1",
    :aws_access_key_id      => ENV['AWS_ACCESS_KEY_ID'],
    :aws_secret_access_key  => ENV['AWS_SECRET_ACCESS_KEY']
  }

  if Rails.env.production?  
    config.cache_dir = "#{Rails.root}/tmp/uploads"
  end

  config.fog_directory  = ENV['AWS_BUCKET']
  config.fog_public     = false
end

Any ideas? 有任何想法吗? Thanks in advance! 提前致谢! :) :)

Always make sure you have the right ENV variables and the the correct S3 keys. 始终确保您拥有正确的ENV变量和正确的S3键。

This was the problem in my case. 就我而言,这就是问题所在。

In my case the problem was related to the ENV on Heroku. 就我而言,问题与Heroku上的ENV有关。 I forgot to add the REGION variable. 我忘了添加REGION变量。

So, it's worth checking if you have all your variables set correctly. 因此,值得检查一下是否正确设置了所有变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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