samedi 28 janvier 2017

nginx 405 - uploading img from ember to rails

I implemented an image upload in Ember, with dropzone addon. Rails 5 is running on the server (Ubuntu 14.x), imagemagick is installed in the Rails Docker Container and all files should go to the folder "uploads". Everything is running as docker containers, so rails, frontend, database and nginx (1.11.4) are seperate containers. Now, if I try to upload an image, the server response is a 405 and rails didn't get anything (nothing in the log).

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 config

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;
  }

}

Request: Request img details

Response: Response img output

If i put the following line into the neginx config (like recommended 100 times on stackoverflow)...

error_page  405     =200 $uri;

... the server throws the error:

Can not read property 'attributes' of undefined

This error message is from dropzone. It can't complete the upload. In rails there is nothing received, no entry in logs, nothing...




Aucun commentaire:

Enregistrer un commentaire