Kubernetes Nginx upload large file 400 No 'Access-Control-Allow-Origin'

9/25/2018

When I keep default of proxy_body_size: 8m of nginx. I can't upload the file size > 8M. Then I configure nginx annotation like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "ingress-name"
  annotations:

    nginx.ingress.kubernetes.io/proxy-body-size: 100m

So, I can upload the files > 8M now. But, I have tried to upload CSV file about 50m, I got an error

Failed to load https://api.domain.xxx/import: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://web.domain.xxx/' is therefore not allowed access. The response had HTTP status code 400.

Anyone can help me to upload the large maximum file is 100m?

Thanks

-- WorkWe
cors
file
kubernetes
kubernetes-ingress
nginx

1 Answer

9/25/2018

The problem is that you are trying to upload the file from a different domain than the one specified in the ingress. It may be the same domain but a different port, protocol (http/https), prefixed with www., etc

By default, the browser doesn't allow those requests, because of security concerns. To allow them you should enable CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Fortunately, it's quite easy to enable CORS in an ingress, just add the following annotations to your api's ingress resource:

nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS"
nginx.ingress.kubernetes.io/cors-allow-origin: "https://web.domain.xxx"

More info about those annotations here

-- Ignacio Millán
Source: StackOverflow