[英]nginx 405 - uploading img from ember to rails
我在Ember中使用dropzone插件(ember-cli-dropzonejs)實現了圖片上傳。 Rails 5在服務器(Ubuntu 14.x)上運行,imagemagick安裝在Rails Docker容器中,所有文件都應轉到文件夾“ uploads”。 一切都作為docker容器運行,因此rails,前端,數據庫和nginx(1.11.4)是單獨的容器。 現在,如果我嘗試上傳圖像,則服務器響應為405,並且Rails沒有得到任何信息(日志中沒有任何內容)。
余燼hbs文件
{{drop-zone url=uploadURL
method='PATCH'
headers=authentication acceptedFiles='.jpg, .jpeg, .gif, .png'
resize=''
maxFilesize='10'
dictDefaultMessage='Upload file'
success=(action 'succesfulFileUpload')
complete=resetUploader
previewTemplate='<div></div>'
uploadprogress=progressManipulation
sending=sending
}}
Rails uploader.rb
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process resize_to_fill: [200, 200]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_whitelist
%w(jpg jpeg gif png)
end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
def filename
return unless original_filename
contenttype = original_filename.split('.').last
"avatar.#{contenttype}"
end
end
Nginx配置
server {
listen 443 ssl;
server_name example.com;
....
ssl stuff
....
location / {
proxy_read_timeout 150;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://backend:3000;
}
}
請求: 請求img詳細信息
響應: 響應img輸出
如果我將以下行放入neginx配置中(如建議在stackoverflow上進行100次)...
error_page 405 =200 $uri;
...服務器拋出錯誤:
Can not read property 'attributes' of undefined
此錯誤消息來自dropzone。 無法完成上傳。 在rails中什么也沒收到,在日志中沒有任何輸入,什么也沒有...
更新和解決方案最后,我修復了它。 問題是把手中的uploadURL錯誤。 在本地使用此錯誤的URL,因為它是相對路徑。 但是在生產中,需要一條可行的道路。
最后我修復了它。 問題是把手中的uploadURL錯誤。 在本地使用此錯誤的URL,因為它是相對路徑。 但是在生產中,需要一條可行的道路。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.