简体   繁体   English

带有AWS S3 +回形针的Rails“缺少必需的:桶选项” —图像上传在Heroku上有效,但在本地不起作用

[英]Rails “missing required :bucket option” w/ AWS S3 + Paperclip — image upload works on Heroku but not locally

I've been trying to make Paperclip (gem version 4.2) work with amazon s3 (gem version 1.66) in a simple blog for two days and would appreciate any advice you all can provide. 我一直试图在一个简单的博客中使Paperclip(4.2版的宝石)与amazon s3(1.66版的宝石)一起工作,并希望大家提供任何建议。

Everything works fine on Heroku--the images upload to my bucket and display correctly--but locally I'm getting the error "missing required :bucket option" when I try to attach an image to an article. 在Heroku上一切正常-图像上传到我的存储桶中并正确显示-但是在本地,当我尝试将图像附加到文章时,出现错误“缺少必需的:bucket选项”。

What am I missing here? 我在这里想念什么?

I've tried the solutions in this and this and this and this related SO post with no luck. 我在这个这个这个以及这个相关的SO帖子中都尝试过解决方案, 但是没有运气。

Thanks. 谢谢。

production.rb and development.rb production.rb和development.rb

config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => ENV['S3_BUCKET_NAME'],
      :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
      }
    }

env.rb env.rb

ENV['s3_bucket'] = 'edited_mybucketname'
ENV['aws_access_key_id'] = 'edited_myaccesskey_id'
ENV['aws_secret_access_key'] = 'edited_mysecretkey'
ENV['AWS_REGION'] = 'us-east-1'

aws.rb aws.rb

AWS.ACCESS_KEY_ID = ENV["AWS_ACCESS_KEY_ID"]
AWS.SECRET_ACCESS_KEY = ENV["AWS_SECRET_ACCESS_KEY"]
AWS.REGION = ENV['AWS_REGION']
S3.BUCKET_NAME = ENV["S3_BUCKET_NAME"]

_form.html.erb _form.html.erb

<%= form_for @article, html: {multipart: true} do |f| %>

  <% if @article.errors.any? %>
    <div id="error_explanation">
      <h2>
        <%= pluralize(@article.errors.count, "error") %> prohibited
        this article from being saved:
      </h2>
      <ul>
        <% @article.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <p>
    <%= f.label :image %><br>
    <%= f.file_field :image %>
  </p>
  <p>
    <%= f.label :title %><br>
    <%= f.text_field :title %>
  </p>

  <p>
    <%= f.label :text %><br>
    <%= f.text_area :text %>
  </p>

  <p>
    <%= f.submit %>
  </p>

<% end %>

show.html.erb show.html.erb

<%= image_tag @article.image.url(:large), :class => "img-responsive" %>

Gemfile 宝石文件

source 'https://rubygems.org'
ruby '2.3.0'

gem 'rails', '4.2.2'

gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem "font-awesome-rails"
gem 'paperclip', '~> 4.2'
gem 'aws-sdk', '~> 1.66'
gem 'simple_form'
gem 'mail_form'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

group :production do
    gem 'rails_12factor', '~> 0.0.3'
end

Case matters with ENV Vars: ENV['s3_bucket'] (from your env.rb files) is not the same as the ENV['S3_BUCKET'] call elsewhere. ENV Vars的大小写有关: ENV['s3_bucket'] (来自您的env.rb文件)与其他地方的ENV['S3_BUCKET']调用不同。

On Heroku, you can run heroku config -a your_app_name | grep bucket 在Heroku上,您可以运行heroku config -a your_app_name | grep bucket heroku config -a your_app_name | grep bucket to confirm that it is indeed uppercased on Heroku. heroku config -a your_app_name | grep bucket以确认它在Heroku上确实是大写的。 (Assuming you're on a *nix machine). (假设您使用的是* nix机器)。

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

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