Hello!
On Mon, Aug 18, 2014 at 10:00 AM, david wrote:
> I am wondering how I would send a get request to openresty that would
> actually perform the upload of local binary content?
>
> so I want to send a request to openresty like
>
> https://domain.com/upload/file.pdf
>
> and then openresty would use the 'file.pdf' to get the data (from a local
> pdf file) and perform the upload to a far end server.
>
The recommended approach is to use the standard Lua "io" module [1]
(or call into the C-level file API functions directly from within Lua
via FFI) to read the file contents from disk in chunks (using chunk
size like 8KB to 32KB). And after reading each data chunk, you send it
immediately to an upstream cosocket object [2] connected to your
remote end. See
Depending on the wire protocol of your remote server, you may also
need to construct the formatted request using formats like "multipart"
as required. But the key here is to prevent buffering the whole file
content in memory (which is very expensive).
Regards,
-agentzh
[1] http://www.lua.org/manual/5.1/manual.html#5.7
[2] https://github.com/openresty/lua-nginx-module#ngxsockettcp