krakend / krakend-ce

KrakenD Community Edition: High-performance, stateless, declarative, API Gateway written in Go.
https://www.krakend.io
Apache License 2.0
1.94k stars 453 forks source link

How to configure Krakend to support Upload File Endpoint #844

Open AnandThurubatla opened 7 months ago

AnandThurubatla commented 7 months ago

Hello Community Members,

We have been using KrakenD as API Gateway for our Micro-Services. One of our micro-service handles Image upload. We tried in ways to configure KrakenD to support upload Image in Base64 format and binary but no luck. Not found any references too.

Can some one share KrakenD configuration which supports Image upload?

Thanks, Anand

alombarte commented 7 months ago

Hello Anand,

You could start here:

  "endpoint": "/some-file-upload",
  "method": "POST",
  "output_encoding": "no-op",
  "input_headers": ["*"],
  "backend": [
    {
      "url_pattern": "/service/some-file-upload",
      "encoding": "no-op",
      "method": "POST",
      "host": ["http://yourmicorservice"]
    }
  ]
}

Notice the no-op because you don't want KrakenD to encode/decode, and also the input_headers because most microservices rely on specific headers for file upload. Use this until you are certain of which ones you need.

Share logs for further help

ridgarou commented 5 months ago

Yes, no-op is the solution.

look, this is how I configured one of my endpoints

   {  
      "endpoint": "/v2/profile/upload-image",
      "method": "POST",
      "input_headers": [ "Content-Type", "Authorization", "Accept-Language" ],
      "input_query_strings": [ ],
      "output_encoding": "no-op",
      "backend": [
        {
          "host": [ "{{ .urls.profile.kube_host_url }}" ],
          "url_pattern": "/profile/upload-image",
          "method": "POST",
          "encoding": "no-op",
          "extra_config": { "backend/http": { "return_error_code": true } }
        }
      ], 
      "extra_config": {
        {{ template "jwt_validator.tmpl" .env.user }}
      }
   }