使用paperclip gem上传图像时,Heroku Rails应用程序崩溃

时间:2016-05-06 22:26:43

标签: ruby-on-rails amazon-web-services heroku amazon-s3 paperclip

你好,我刚刚在heroku上部署了我的应用程序,但我收到的错误是“我们很抱歉,但是出了点问题。”#34;每当我尝试将头像图像添加到编辑或创建表单中的某个部分时。我安装了以下gem(paperclip和aws),并且还存储了Amazon Web服务凭证。

UPDATE 忘了包括我的回形针配置

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'],
    :s3_region => ENV['AWS_REGION'],
    }

我为我的存储区设置了一个区域,并设置了所有其他凭据。

以下是来自纸质记录的更多日志

May 06 17:26:29 blooming-stream-56631 app/web.1:    User Load (0.8ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 3]] 
May 06 17:26:29 blooming-stream-56631 app/web.1:    Cart Load (0.6ms)  SELECT  "carts".* FROM "carts" WHERE "carts"."user_id" = $1 LIMIT 1  [["user_id", 3]] 
May 06 17:26:29 blooming-stream-56631 app/web.1:    Part Load (0.6ms)  SELECT  "parts".* FROM "parts" WHERE "parts"."active" = $1 AND "parts"."id" = $2 LIMIT 1  [["active", "t"], ["id", 3]] 
May 06 17:26:29 blooming-stream-56631 app/web.1:     (2.0ms)  BEGIN 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: file -b --mime '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-egfg1e.jpg' 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-nim88m.jpg[0]' 2>/dev/null 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: identify -format %m '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-nim88m.jpg[0]' 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: convert '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-nim88m.jpg[0]' -auto-orient -resize "100x100>" '/tmp/64590094a1bc5d8dad223b9548f3160320160507-3-8wa2ey' 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-nim88m.jpg[0]' 2>/dev/null 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: identify -format %m '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-nim88m.jpg[0]' 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: convert '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-nim88m.jpg[0]' -auto-orient -resize "x200" -crop "200x200+39+0" +repage '/tmp/64590094a1bc5d8dad223b9548f3160320160507-3-1897liw' 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-nim88m.jpg[0]' 2>/dev/null 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: identify -format %m '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-nim88m.jpg[0]' 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: convert '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-nim88m.jpg[0]' -auto-orient -resize "300x300>" '/tmp/64590094a1bc5d8dad223b9548f3160320160507-3-jmofxi' 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Command :: file -b --mime '/tmp/9a5736fc6ab3ef6c4c315e0672d4cd2820160507-3-71n03p.jpg' 
May 06 17:26:29 blooming-stream-56631 app/web.1:    SQL (0.7ms)  UPDATE "parts" SET "avatar_file_name" = $1, "avatar_content_type" = $2, "avatar_file_size" = $3, "avatar_updated_at" = $4 WHERE "parts"."id" = $5  [["avatar_file_name", "car-parts-tampa.jpg"], ["avatar_content_type", "image/jpeg"], ["avatar_file_size", 66700], ["avatar_updated_at", "2016-05-07 00:26:29.247325"], ["id", 3]] 
May 06 17:26:29 blooming-stream-56631 app/web.1:  [paperclip] saving /parts/avatars/000/000/003/original/car-parts-tampa.jpg 
May 06 17:26:29 blooming-stream-56631 app/web.1:     (0.6ms)  ROLLBACK 
May 06 17:26:29 blooming-stream-56631 app/web.1:  Completed 500 Internal Server Error in 231ms (ActiveRecord: 5.4ms) 
May 06 17:26:29 blooming-stream-56631 app/web.1:  NameError (uninitialized constant Paperclip::Storage::S3::AWS): 
May 06 17:26:29 blooming-stream-56631 app/web.1:    app/controllers/parts_controller.rb:31:in `update' 
May 06 17:26:29 blooming-stream-56631 heroku/router:  at=info method=POST path="/parts/3" host=blooming-stream-56631.herokuapp.com request_id=4002a6c5-61df-46db-9d28-0a49cc679a7f fwd="67.85.136.99" dyno=web.1 connect=2ms service=486ms status=500 bytes=1754 

宝石

gem 'paperclip'
gem 'aws-sdk', '~> 2.3'

零件模型

class Part < ActiveRecord::Base
  has_attached_file :avatar, styles: {
    thumb: '100x100>',
    square: '200x200#',
    medium: '300x300>'
  }

  validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/

部分视图(创建)

<%= form_for(@part, multipart: true) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %><br>


<%= f.label :description %>
<%= f.text_field :description%><br>

<%= f.label :category_id%>
<%= f.collection_select :category_id, Category.all, :id, :name%><br>

<%= f.label :discount%>
<%= f.number_field :discount%>%<br>

<%= f.label :price%>
<%= f.text_field :price%><br>

<div class="field">
  <%= f.label :avatar%>
  <%= f.file_field :avatar%>
</div>
<%=f.submit %>
<%end%>

如果有人需要更多信息,我们很乐意提供更新。

2 个答案:

答案 0 :(得分:0)

尝试将您的凭据设为自己的哈希,而不包括其他元素。像这样:

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

另外,不要忘记在heroku中设置ENV变量!

答案 1 :(得分:0)

好的,事实证明我设置的区域不正确我通过将区域更改为他们正在寻找的正确格式来使其工作