[luci] LuCI Web Interface for Upload/Download of files

Jo-Philipp Wich xm at subsignal.org
Tue Jun 26 14:22:57 CEST 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

> I have been working on porting the Pirate Box project to OpenWRT. I
> am using the LuCI interface instead of the existing Python based
> web interface "Droopy." I have been working with existing chunks of
> code and modifying them for my purposes.

Great to hear that!

> Knowing that meta.name is the "name" element of a submitted form.
> Is there an equivalent object for the name of the uploaded file? I
> have looked over the luci.lua code that defines the handler
> function and cannot seem to parse it out from there. I would like
> to use the file name to define the FILE_NAME variable.

The meta.file field should contain the client side file name (it is
taken from the Content-Disposition header sent along with the POST).

> I am using the filebrowser.htm view to allow a user to browse the 
> directory where files are uploaded. I am having difficulty sending
> a href back to the Lua (luci.ltn12.pump.all) controller code to
> allow a user to download the file. I can't seem to find the correct
> way to send the location from the clicked link to the lua backend
> to initiate the download.

Yes, the filebrowser.htm view was once built to allow the user to pick
a file from the router fs, which will then copy the corresponding path
into the calling text input field.

In order to support your use case the file browser widget must be
extended to execute a callback in the opening page when a file has
been clicked.

If you have a specific idea on how the widget should behave we can
consider to implement it.

> My last question is about the luci.ltn12.pump.all function. If I
> do have a path to a file on a router (or attached USB drive) can I
> simple use that path as the source and luci.http.write as the sink
> to send a file to a user?

Yes. The usual approach is this:

  ltn12.pump.all(ltn12.source.file("/some/path.bin"), luci.http.write)


However it might be more efficient to offload this task to the web
server, this way you don't have to funnel the data through your Lua
controller in order to feed it to the client.


HTH,
Jow
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk/pqZ0ACgkQdputYINPTPN+xACfSHzsjKIdW0s9fujXpmzKOtAc
JWcAnRC6WoXVt1BrtlYDthZHAzFKTVg1
=2hz1
-----END PGP SIGNATURE-----


More information about the luci mailing list