[LEDE-DEV] Luci's HTTP API

Levente leventelist at gmail.com
Fri Sep 8 00:50:04 PDT 2017


Dear LEDE developers,


Maybe this is off topic, but I'm trying to use LUCI's HTTP protocol
parser library for to upload a file to the system. I find very little
documentation on this.

I have the following code that obviously does nothing. Could you help
me add the missing parts?


http = require "luci.http"
proto = require "luci.http.protocol"


local fileOpened = 0
local fileP

function filecb(t, data, isLast)

    if fileOpened == 0 then
        FileP = io.open("/tmp/blabla", "wb")
        fileOpened = 1
    end

    FileP:write(data)

    if isLast then
        io.close(FileP)
    end

end


src = http.source()
httpMsg = proto.parse_message_header(src)

proto.parse_message_body(src, httpMsg, filecb)

http.close()


So I experience that http.source() is not even returns. It dies with this error:

/usr/bin/lua: /usr/lib/lua/luci/http.lua:193: attempt to index field
'request' (a nil value)
stack traceback:
    /usr/lib/lua/luci/http.lua:193: in function 'source'
    ./config_v2.sh:27: in main chunk
    [C]: ?

Browsing the source code this call shall return

context.request.input

So the question is how to initialize that?


Thank you,
Levente



More information about the Lede-dev mailing list