Kong / kong-js-pdk

Kong PDK for Javascript and plugin server
Apache License 2.0
35 stars 17 forks source link

Accessing Binary Files in plugin #395

Open ashutoshmadhwani opened 7 months ago

ashutoshmadhwani commented 7 months ago

I am writing a custom js plugin for kong where I need to access the binary files that are coming with request as multipart form data Currently I am using the getRawBody function provided by kong-pdk, but I am getting following error

2024/02/19 11:41:36 [warn] 1293#0: *2580 a client request body is buffered to a temporary file /var/run/kong/client_body_temp/0000000002" 2024/02/19 11:41:36 [error] 1293#0: *2580 [kong] init.lua:405 [clacks] /usr/local/share/lua/5.1/MessagePack.lua:126: attempt to get length of local 'str' (a nil value)

Is there a way to resolve it Basically I want to access the number of files uploaded, size of files and the file extension

brentos commented 7 months ago

Kong has a KB article about this, you need to increase the client_body_buffer_size: https://support.konghq.com/support/s/article/Kong-plugin-produces-a-warning-a-client-request-body-is-buffered-to-a-temporary-file

ashutoshmadhwani commented 7 months ago

@brentos The request is directly coming to kong, there is no nginx cinfigured, Is there a way to configure this value in kong directly

brentos commented 7 months ago

Kong runs on nginx, so that is why we are setting this nginx variable. You either set this in kong.conf: nginx_http_client_body_buffer_size

Or as a Kong environment variable: KONG_NGINX_HTTP_CLIENT_BODY_BUFFER_SIZE