Libraryless. Click here for Pure Java version (11426L/68K).
1 | static S uploadFileToFileServer(S pathOrURL) { |
2 | File f = urlToFileOpt(pathOrURL); |
3 | if (f != null) |
4 | ret uploadFileToFileServer(f); |
5 | else if (isURL(pathOrURL)) { |
6 | File tmp = createTempFile(); |
7 | afterwards { deleteFile(tmp); } |
8 | loadBinaryPageToFile(pathOrURL, tmp); |
9 | ret uploadFileToFileServer(tmp, pathOrURL); |
10 | } else |
11 | ret uploadFileToFileServer(newFile(pathOrURL)); |
12 | } |
13 | |
14 | static S uploadFileToFileServer(File f) { |
15 | ret uploadFileToFileServer(f, f.getName()); |
16 | } |
17 | |
18 | // TODO: optimize |
19 | static S uploadFileToFileServer(File f, S name) { |
20 | assertFileExists(f); |
21 | ret uploadFileToFileServer(loadBinaryFile(f), name); |
22 | } |
23 | |
24 | static S uploadFileToFileServer(byte[] data, S name) { |
25 | print("Uploading " + l(data) + " bytes (" + quote(name) + ") to file server."); |
26 | S page = postPage("https://botcompany.de/files/upload", "data", bytesToHex(data), "name", name, '_pass, muricaPassword()); |
27 | print(page); |
28 | Matcher m = Pattern.compile("/raw/([0-9]+)").matcher(page); |
29 | if (!m.find()) fail("File server said: " + page); |
30 | S url = "https://botcompany.de/files/" + m.group(1); |
31 | infoBox("Uploaded: " + url); |
32 | ret url; |
33 | } |
Began life as a copy of #1010476
download show line numbers debug dex old transpilations
Travelled to 19 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, omdjrrnzbjjv, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, snaazhdonpnp, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1015418 |
Snippet name: | uploadFileToFileServer - returns URL or fails |
Eternal ID of this version: | #1015418/17 |
Text MD5: | a25f32dfcf0c57d960e4cc4d5119903b |
Transpilation MD5: | bc39c8d83a7e419afdb4affb85c4f689 |
Author: | stefan |
Category: | javax / networking |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-28 15:14:19 |
Source code size: | 1150 bytes / 33 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 430 / 722 |
Version history: | 16 change(s) |
Referenced in: | [show references] |