Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 尝试使用AS3在Heroku web app上上载图片时出错(正在制作中)Michael Hartl第11章_Ruby On Rails_Heroku_Amazon Web Services_Amazon S3_Railstutorial.org - Fatal编程技术网

Ruby on rails 尝试使用AS3在Heroku web app上上载图片时出错(正在制作中)Michael Hartl第11章

Ruby on rails 尝试使用AS3在Heroku web app上上载图片时出错(正在制作中)Michael Hartl第11章,ruby-on-rails,heroku,amazon-web-services,amazon-s3,railstutorial.org,Ruby On Rails,Heroku,Amazon Web Services,Amazon S3,Railstutorial.org,我正在做迈克尔·哈特尔的教程。第十一章 我的应用程序在产品中上传图片,但在我部署它时不会上传,但是文本MicroPost确实可以工作,所以问题出在AmazonS3的某个地方 我已将S3上的权限设置为“everyone”,以便在我的bucket上上载/删除 我已经使用rails控制台在我的heroku帐户上设置了正确的S3键,使其不包含在代码中(正如教程所建议的) 以下是我尝试在web应用程序上上载内容时出现的错误消息的副本: 2014-11-07T10:25:23.192777+00:00 ap

我正在做迈克尔·哈特尔的教程。第十一章

我的应用程序在产品中上传图片,但在我部署它时不会上传,但是文本MicroPost确实可以工作,所以问题出在AmazonS3的某个地方

我已将S3上的权限设置为“everyone”,以便在我的bucket上上载/删除

我已经使用rails控制台在我的heroku帐户上设置了正确的S3键,使其不包含在代码中(正如教程所建议的)

以下是我尝试在web应用程序上上载内容时出现的错误消息的副本:

2014-11-07T10:25:23.192777+00:00 app[web.1]:    (2.2ms)  BEGIN
2014-11-07T10:25:23.198717+00:00 app[web.1]:   SQL (2.1ms)  INSERT INTO "microposts" ("content", "created_at", "picture", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["content", "Wont work "], ["created_at", "2014-11-07 10:25:23.194942"], ["picture", "BALI_BLOG.jpg"], ["updated_at", "2014-11-07 10:25:23.194942"], ["user_id", 101]]
2014-11-07T10:25:28.198243+00:00 heroku[router]: at=info method=POST path="/microposts" host=cryptic-falls-5768.herokuapp.com request_id=eb6bfb98-4146-4268-aaec-817aa15c7e51 fwd="114.129.16.105" dyno=web.1 connect=1ms service=6
632ms status=500 bytes=1786
2014-11-07T10:25:28.195098+00:00 app[web.1]: Completed 500 Internal Server Error in 5613ms
2014-11-07T10:25:28.197697+00:00 app[web.1]: excon.error.response
2014-11-07T10:25:28.197714+00:00 app[web.1]:     "x-amz-request-id" => "75844FA2260D74EC"
2014-11-07T10:25:28.197695+00:00 app[web.1]: Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden)
2014-11-07T10:25:28.197712+00:00 app[web.1]:     "x-amz-id-2"       => "9Lm1JyP7J8nLkOhAo0eXtlmoaR2bBf+tJj6z0WZWApxAiRO1n7gCwWtWer5LrkH8RLCKf4K4Eg4="
2014-11-07T10:25:28.193952+00:00 app[web.1]:    (2.1ms)  ROLLBACK
2014-11-07T10:25:28.197715+00:00 app[web.1]:   }
2014-11-07T10:25:28.197717+00:00 app[web.1]:   :local_address => "172.18.66.78"
2014-11-07T10:25:28.197718+00:00 app[web.1]:   :local_port    => 22004
2014-11-07T10:25:28.197720+00:00 app[web.1]:   :reason_phrase => "Forbidden"
2014-11-07T10:25:28.197721+00:00 app[web.1]:   :remote_ip     => "54.231.242.81"
2014-11-07T10:25:28.197723+00:00 app[web.1]:   :status        => 403
2014-11-07T10:25:28.197724+00:00 app[web.1]: ):
2014-11-07T10:25:28.197706+00:00 app[web.1]:     "Connection"       => "close"
2014-11-07T10:25:28.197725+00:00 app[web.1]:   app/controllers/microposts_controller.rb:7:in `create'
2014-11-07T10:25:28.197708+00:00 app[web.1]:     "Content-Type"     => "application/xml"
2014-11-07T10:25:28.197727+00:00 app[web.1]: 
2014-11-07T10:25:28.197711+00:00 app[web.1]:     "Server"           => "AmazonS3"
2014-11-07T10:25:28.197728+00:00 app[web.1]: 
2014-11-07T10:25:28.197692+00:00 app[web.1]: 
2014-11-07T10:25:28.197703+00:00 app[web.1]:   :body          => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>75844FA2260D74EC</RequestId><HostId>9Lm1JyP7J8nLkOhAo0eXtlmoaR2bBf+tJj6z0WZWApxAiRO1n7gCwWtWer5LrkH8RLCKf4K4Eg4=</HostId></Error>"
2014-11-07T10:25:28.197705+00:00 app[web.1]:   :headers       => {
2014-11-07T10:25:28.197709+00:00 app[web.1]:     "Date"             => "Fri, 07 Nov 2014 10:25:27 GMT"
此外,以下是相关文件中的代码:

/config/initializers/carrier_wave.rb

if Rails.env.production?
  CarrierWave.configure do |config|
    config.fog_credentials = {
      # Configuration for Amazon S3
      :provider              => 'AWS',
      :aws_access_key_id     => ENV['S3_ACCESS_KEY'],
      :aws_secret_access_key => ENV['S3_SECRET_KEY'],
      :region  => ENV['S3_REGION']
    }
    config.fog_directory     =  ENV['S3_BUCKET']
  end
end
congig/环境/生产

    Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Enable Rack::Cache to put a simple HTTP cache in front of your application
  # Add `rack-cache` to your Gemfile before enabling this.
  # For large-scale production use, consider using a caching reverse proxy like
  # NGINX, varnish or squid.
  # config.action_dispatch.rack_cache = true

  # Disable Rails's static asset server (Apache or NGINX will already do this).
  config.serve_static_assets = false

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
  # yet still be able to expire them through the digest params.
  config.assets.digest = true

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
   config.force_ssl = true

  # Decrease the log volume.
  # config.log_level = :info

  # Prepend all log lines with the following tags.
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups.
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  host = 'cryptic-falls-5768.herokuapp.com'
  config.action_mailer.default_url_options = { host: host }
  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
   }
  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end
这是我第一次真正部署web应用程序,也是第一次使用S3,但我严格遵循了每一步,并在键入后验证了我的代码是否与教程中的代码完全相同

请让我知道,如果有任何额外的代码,我可以提供帮助解决这个问题


谢谢你

我通过将初始值设定项文件名改为carrierwave.rb而不是carrier\u wave.rb来解决问题

if Rails.env.production?
  CarrierWave.configure do |config|
    config.fog_credentials = {
      # Configuration for Amazon S3
      :provider              => 'AWS',
      :aws_access_key_id     => ENV['S3_ACCESS_KEY'],
      :aws_secret_access_key => ENV['S3_SECRET_KEY'],
      :region  => ENV['S3_REGION']
    }
    config.fog_directory     =  ENV['S3_BUCKET']
  end
end

希望这能奏效。

我也有同样的问题。我认为这是一个权限问题,而且您的日志似乎也在这样说。查看AWS控制台上的IAM仪表板。确保该用户是某个组的成员,并且该组具有管理员级别的权限。这个给我修好了


祝你好运

我发现这个答案很有帮助。

您需要将amazons3fullaccess策略附加到用户


设置IAM用户时,amazon演练会告诉您将策略附加到bucket本身。他们给出的示例仅包括bucket的putobject和getobject操作。但是我认为上传需要很多操作的权限

我也有同样的问题。原来是亚马逊地区的名字,有点棘手。我的bucket在AWS界面中被列为“Ireland”,但它必须在Rails/Heroku中被称为“eu-west-1”