[英]Can't upload images with Rails and Paperclip
I'm using Paperclip in my Rails app to handle image uploads. 我在Rails应用程序中使用Paperclip来处理图像上传。 However, for some reason, every time I try to create a model instance that has an attached image, I'm getting a Rails 500 error.
但是,由于某种原因,每次我尝试创建具有附加图像的模型实例时,都会遇到Rails 500错误。
What's strange is that restarting the app (via Upstart) then resubmitting the form allows me to upload images successfully, but it doesn't seem to "take": any subsequent uploads still give me a 500 error. 奇怪的是,重新启动应用程序(通过Upstart)然后重新提交表单使我能够成功上传图像,但似乎并没有“花”:任何后续上传仍然会给我500错误。
The production log is unhelpful and doesn't even show the POST request made to create the instance. 生产日志无济于事,甚至不显示创建实例的POST请求。
My Upstart config file: 我的Upstart配置文件:
description 'site.com'
author 'Daniel J. <>'
start on [2345]
stop on runlevel [016]
env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env RAILS_ENV=production
env SECRET_KEY_BASE=''
env DEVISE_SECRET_KEY=''
env POSTGRESQL_PASSWORD=''
setuid www-data
setgid www-data
chdir /var/www/site/current
pre-start exec bundle exec unicorn_rails -D -c /var/www/site/current/config/unicorn.rb --env production
post-stop exec kill `cat /var/www/site/current/tmp/pids/unicorn.pid`
My nginx file: 我的nginx文件:
upstream app {
server 127.0.0.1:3000;
}
server {
listen 80 default;
server_name site.com;
charset utf-8;
client_max_body_size 75M;
root /var/www/site/current/public;
location ~ ^/(assets)/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location / {
try_files $uri/index.html $uri @app;
error_page 404 /404.html;
error_page 403 /403.html;
error_page 422 /422.html;
error_page 500 502 503 504 /500.html;
}
location = /favicon.ico {
expires max;
add_header Cache-Control public;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
}
And my Unicorn config file: 和我的独角兽配置文件:
listen 3000
worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3)
timeout 30
preload_app true
working_directory '/var/www/site/current'
stderr_path 'log/unicorn-error.log'
stdout_path 'log/unicorn-access.log'
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT.'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
I figured out that it was a lack of memory on the box that did it. 我发现这样做的原因是包装盒上没有记忆。 Once I added a swapfile (using the instructions here: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04 ), I was able to successfully upload files.
添加交换文件后(使用此处的说明: https : //www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04 ),我就能够成功上传文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.