Libraryless. Click here for Pure Java version (4745L/35K/96K).
!752 static S dir = "/storage/sdcard0"; p { serveHttp(7777); run("#1000842"); // upload server on 8888 } static NanoHTTPD.Response serve(S uri, NanoHTTPD.Method method, Map<S,S> header, Map<S,S> params, Map<S,S> files) { print("Serving HTML."); File d = new File(dir); File sub = new File(dir, dropPrefix("/", uri)); print("File: " + sub.getAbsolutePath() + ", exists: " + sub.exists()); S html; if (!sub.exists()) html = "Not found: " + quote(f2s(sub)) + " (uri: " + quote(uri) + ")"; else if (sub.isFile()) ret serveFile(sub); else html = fileLinks(findAllFiles(sub), d); ret serveHTML(htitle("Phone Server.") + p(href("http://" + getMyIP() + ":8888", "Upload stuff")) + h3(sub.getAbsolutePath()) + html); } static S fileLinks(L<File> files, File rootDir) { new L<S> l; for (File f : files) { S path = getRelPath(f, rootDir); l.add(href(urlencode(dropPrefix("/", path)), path)); } ret ul(l); } static S getRelPath(File f, File root) ctex { ret dropPrefix(root.getCanonicalPath(), f.getCanonicalPath()); }
Began life as a copy of #1001649
download show line numbers debug dex old transpilations
Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, crvwmplrxojx, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, nbgitpuheiab, onxytkatvevr, pnmttuucjkfb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002646 |
Snippet name: | "Phone Server" - Serve local directory (HTTP, Android, unprotected, WORKS) |
Eternal ID of this version: | #1002646/1 |
Text MD5: | 43465667c5bf32b99054ea9438c26d1e |
Transpilation MD5: | 51fe98f7da18bcb947b85cddb8afde46 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-12-13 01:00:53 |
Source code size: | 1125 bytes / 43 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 885 / 1070 |
Referenced in: | #1005938 - "Phone Server" - Serve local directory (HTTP, Android, weakly password-protected) #3000382 - Answer for ferdie (>> t = 1, f = 0) |