Thanks.
That might work inside LUCI. I'm sorry, I wasn't clear enough. I want to use the library to actually create my own web application. I don't want to integrate it into LUCI. But thanks anyways. :-) Levente On Fri, Sep 8, 2017 at 12:15 PM, Karl Palsson <ka...@tweak.net.au> wrote: > > Here's a snippet I've used to accept HTTP POST of a file to in > luci... > > http = require("luci.http") > > > local method = http.getenv("REQUEST_METHOD") > local pathinfo = http.getenv("PATH_INFO") -- from luci > > > --- if method == post and path info == allowed for your requirements. > > http.setfilehandler( > function(meta, chunk, eof) > -- If this was multipart form, make sure to only accept the > documented form field. > -- return true to continue with subsequent chunks. > if meta and (meta.name ~= "raw") then return true end > if not file then > -- Don't trample a file if we don't get any data. > if not chunk then return false end > file = io.open(file_path, "w") > end > if chunk then > file:write(chunk) > end > if eof then > file:close() > end > return true > end > ) > -- trigger handler! > http.content() > > > Cheers, > Karl P > > > Levente <leventel...@gmail.com> wrote: >> 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 >> >> _______________________________________________ >> Lede-dev mailing list >> Lede-dev@lists.infradead.org >> http://lists.infradead.org/mailman/listinfo/lede-dev _______________________________________________ Lede-dev mailing list Lede-dev@lists.infradead.org http://lists.infradead.org/mailman/listinfo/lede-dev