<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection">Yes, these suggestions worked. Thanks!</div>
<div name="messageReplySection">On Oct 30, 2018, 2:14 AM -0700, Dmitry Volyntsev <xeioex@nginx.com>, wrote:<br />
<blockquote type="cite"><br class="" />
<div><br class="" />
<blockquote type="cite" class="">
<div class="">On 29 Oct 2018, at 23:44, Jonathan Esterhazy <<a href="mailto:jonathan.esterhazy@gmail.com" class="">jonathan.esterhazy@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline" />
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class="">Hello!</div>
<div class=""><br class="" /></div>
<div class="">I am trying to use njs (ngx_http_js_module) to modify POSTed request data before sending to an upstream api. Using the req.requestBody function works fine for small requests, but for larger ones causes this error:<br class="" /></div>
<div class=""><br class="" /></div>
<div class="">[error] 14#14: *18 js exception: Error: request body is in a file<br class="" /></div>
<div class=""><br class="" /></div>
<div class="">If I was using the Lua module, I could use ngx.req.get-body_file function to get this data, but there doesn't seem to be any way to do that in njs. Did I miss something? Is there a way to access the data or find out the filename?<br class="" /></div>
</div>
</div>
</div>
</div>
</blockquote>
<div><br class="" /></div>
<div><br class="" /></div>
<div>Hi Jonathan!</div>
<div><br class="" /></div>
<div>You have two options here:</div>
<div><br class="" /></div>
<div>1) you can increase the client buffers</div>
<div><br class="" /></div>
<div>According to the documentation:</div>
<div>
<div><a href="http://nginx.org/en/docs/njs/reference.html#http" class="">http://nginx.org/en/docs/njs/reference.html#http</a></div>
<div class=""><br class="" /></div>
</div>
<div>
<div>r.requestBody</div>
<div>returns the client request body if it has not been written to a temporary file. To ensure that the client request body is in memory, its size should be limited by client_max_body_size, and a sufficient buffer size should be set using client_body_buffer_size.</div>
</div>
<div><br class="" /></div>
<div>2) you can open the file with the client’s request using request_body_file variable (<a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_body_file" class="">http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_body_file</a>)</div>
<div><br class="" /></div>
<div>var fs = require(‘fs’);</div>
<div>var large_body = fs.readFileSync(r.variables.request_body_file)</div>
<div><br class="" /></div>
<br class="" />
<blockquote type="cite" class="">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div dir="ltr" class=""><br class="" /></div>
</div>
</div>
_______________________________________________<br class="" />
nginx mailing list<br class="" />
<a href="mailto:nginx@nginx.org" class="">nginx@nginx.org</a><br class="" />
http://mailman.nginx.org/mailman/listinfo/nginx</div>
</blockquote>
</div>
<br class="" /></blockquote>
</div>
</body>
</html>