Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure Krakend to support Upload File Endpoint #844

Open
AnandThurubatla opened this issue Feb 13, 2024 · 5 comments
Open

How to configure Krakend to support Upload File Endpoint #844

AnandThurubatla opened this issue Feb 13, 2024 · 5 comments
Labels

Comments

@AnandThurubatla
Copy link

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
Copy link
Member

alombarte commented Feb 13, 2024

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
Copy link

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

@qtpi-bonding
Copy link

Hello,

I am in a similar situation. I have KrakenD and SeaweedFS in my docker compose.

I am able to get images by directly accessing the SeaweedFS container but not if it goes through KrakenD.

Here is how I have configured KrakenD.

{ "endpoint": "/seaweedfs/{segment1}/{segment2}/{segment3}/", "method": "GET", "output_encoding": "no-op", "input_headers": ["*"], "backend": [ { "method": "GET", "encoding": "no-op", "url_pattern": "/{segment1}/{segment2}/{segment3}/", "host": [ "http://seaweedfs:8333" ] } ] }

However, when going through KrakenD, I receive this error:

NotImplementedA header you provided implies functionality that is not implemented/default-bucket/media/image_1.png

Any suggestions would be greatly appreciated.

@alombarte
Copy link
Member

Hello @qtpi-bonding, the error message you are seeing is provided by SeaweedFS. The KrakenD configuration looks OK and there is nothing much we can do from here. I guess this is a generic service error (I saw this on AWS Amplify) and might have nothing to do with headers. Something like special chars, hyphens, etc, could be raising this error. In any case, if headers were a problem for your backend, try to pass them one by one so you can discard if there is any header.
KrakenD config is all right.

@qtpi-bonding
Copy link

Thank you for your help, @alombarte.

I have posted a more detailed question here: #950

I tried manually adding all the headers back in a curl request from the KrakenD container to SeaweedFS container and it worked. This leads me to suspect KrakenD is adding extra headers or not showing all the headers when I look at the debug endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants