在我的Rails应用中,我使用的是carrierwave-aws
(不是fog
)。它适用于开发和heroku local
中的图像上传,但是当我部署它时,我得到了这个heroku log
...
2016-05-11T09:54:48.072165+00:00 app[web.1]: Started POST "/users" for 110.168.231.136 at 2016-05-11 09:54:48 +0000
2016-05-11T09:54:48.076592+00:00 app[web.1]: Processing by UsersController#create as HTML
2016-05-11T09:54:48.076888+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"fa9b1wD30+tzdF3hxs+sMipSmr/jZLeT/x39S8djQXf9DmfTv/dkhpiIjPiy8ufg//oGdTT+QMvGCRJDtYk08w==", "user"=>{"guest"=>"true", "nickname"=>"", "first_name"=>"Mary", "last_name"=>"Smith", "gender"=>"female", "email"=>"test@example.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "zip"=>"55544", "face_photo"=>#<ActionDispatch::Http::UploadedFile:0x0056329c909d20 @tempfile=#<Tempfile:/tmp/RackMultipart20160511-12-17ng6dj.png>, @original_filename="CEP image13.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"user[face_photo]\"; filename=\"CEP image13.png\"\r\nContent-Type: image/png\r\n">}}
2016-05-11T09:54:48.081994+00:00 app[web.1]: Completed 500 Internal Server Error in 5ms
2016-05-11T09:54:48.333865+00:00 heroku[router]: at=info method=POST path="/users" host=example.com request_id=6ce23206-cf2c-7705-ae3c-ce39bdb8bd19 fwd="110.168.231.136,110.168.231.136" dyno=web.1 connect=1ms service=4061ms status=500 bytes=1669
2016-05-11T09:54:49.167666+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=example.com request_id=6587b42e-475f-4431-834d-200a2c994126 fwd="110.168.231.136" dyno=web.1 connect=0ms service=20ms status=301 bytes=802
2016-05-11T09:54:49.159482+00:00 app[web.1]: Started GET "/favicon.ico" for 110.168.231.136 at 2016-05-11 09:54:49 +0000
2016-05-11T09:54:49.876909+00:00 app[web.1]: Started GET "/" for 110.168.231.136 at 2016-05-11 09:54:49 +0000
2016-05-11T09:54:49.884058+00:00 app[web.1]: Processing by PagesController#front as */*
2016-05-11T09:54:49.890819+00:00 app[web.1]: Rendered pages/front.html.erb within layouts/application (1.5ms)
2016-05-11T09:54:49.892156+00:00 app[web.1]: Rendered shared/_messages.html.erb (0.1ms)
2016-05-11T09:54:49.892539+00:00 app[web.1]: Completed 200 OK in 8ms (Views: 5.4ms | ActiveRecord: 0.0ms)
2016-05-11T09:54:49.905696+00:00 heroku[router]: at=info method=GET path="/" host=example.com request_id=54e56ee8-3422-45c3-aa51-34614224d6db fwd="110.168.231.136,110.168.231.136" dyno=web.1 connect=1ms service=31ms status=200 bytes=1791
你会在这个日志中注意到Completed 500 Internal Server Error
- 当我拿出图像上传器时我没有得到(所以这绝对是一个上传者的问题)。顺便说一句,fog
发生了同样的事情,所以这不是问题所在。错误似乎发生在我在Rails 4中的create
操作的开始。
这是我的config/initializers/carrier_wave.rb
CarrierWave.configure do |config|
config.storage = :aws
config.aws_bucket = ENV.fetch('S3_BUCKET')
config.aws_acl = 'public-read'
config.aws_authenticated_url_expiration = 60 * 60 * 24 * 7
config.aws_attributes = {
expires: 1.week.from_now.httpdate,
cache_control: 'max-age=604800'
}
config.aws_credentials = {
access_key_id: ENV.fetch('S3_KEY'),
secret_access_key: ENV.fetch('S3_SECRET'),
region: ENV.fetch('S3_REGION') # Required
}
config.cache_dir = "#{Rails.root}/tmp/uploads"
end
根据https://github.com/carrierwaveuploader/carrierwave/wiki/how-to%3A-make-carrierwave-work-on-heroku中的建议,我为/tmp/uploads
添加了cache_dir
,但无济于事。这是我的上传者......
class FacePhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process :resize_to_fill => [156, 200]
storage :aws
def cache_dir
"#{Rails .root}/tmp/uploads"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
我强调这在我上面提到的其他环境中运行良好。仅部署在Heroku
我才有500 Internal Server Error
。我很困惑。