[luci] luci.http.setfilehandler function not called
Federico Fissore
federico at fissore.org
Sat May 25 16:46:03 CEST 2013
Hi everyone
I've solved the problem by putting the call to setfilehandler into
index() function body
Debugging with some prints, I've found that the code that should have
called my handler was called BEFORE the handler was set up, so it found
"nil" and ignored the file
in the handler I had to check if path_info matches the desired one and
also to put the uploaded file name in a custom environment variable
in the upload() function I then manage the uploaded file, making things
with it
in essence: ugly and dirty
Could it be caused by the fact that i'm NOT using cbi, but building the
view and handling the requests on my own?
federico
Federico Fissore, il 23/05/2013 18:28, ha scritto:
> Hi everyone
>
> I'm trying to handle a file upload with function
>
> function upload()
> local fp
> luci.http.setfilehandler(function(meta, chunk, eof)
> if not fp and meta and meta.name == "image" then
> local filename = luci.http.formvalue("sketch")
> fp = io.open("/tmp/" .. filename, "w")
> end
> if fp then
> if chunk then
> fp:write(chunk)
> end
> if eof then
> fp:close()
> end
> end
> end)
> end
>
> configured with
>
> entry({ "image", "upload" }, call("upload"), _("My Web Panel"), 10)
>
> Problem is that that function is not called at all
>
> I'm using luci branch 0.11 from
> http://svn.luci.subsignal.org/luci/branches/luci-0.11
>
> Any hints? I'm quite stuck... :(
> _______________________________________________
> luci mailing list
> luci at lists.subsignal.org
> https://lists.subsignal.org/mailman/listinfo/luci
>
More information about the luci
mailing list