Uses 278K of libraries. Click here for Pure Java version (2321L/16K/52K).
1 | !752 |
2 | |
3 | lib 1004792 // commons codec |
4 | |
5 | import org.apache.commons.codec.net.URLCodec; |
6 | |
7 | static boolean test; |
8 | |
9 | p { |
10 | S name = args[0]; // put file name here |
11 | if (args.length > 1 && args[1].equals("test")) |
12 | test = true; |
13 | name = new File(name).getAbsolutePath(); |
14 | byte[] data = loadBinaryFile(name); |
15 | if (data == null) |
16 | print("File not found: " + name); |
17 | else |
18 | if (test) |
19 | print(binaryUrlencode(data)); |
20 | else |
21 | uploadData("data-uploader " + programID(), "Data file " + name + " from " + computerID(), data, false); |
22 | } |
23 | |
24 | static String uploadData(String gummipw, String title, byte[] data, boolean superhigh) throws IOException { |
25 | if (gummipw == null || gummipw.length() == 0) |
26 | throw new RuntimeException("Need gummi password."); |
27 | |
28 | System.out.println("Uploading:"); |
29 | System.out.println(" gummipw: " + gummipw); |
30 | System.out.println(" " + title); |
31 | int displayLength = 40; |
32 | System.out.println(" " + data.length + " bytes of data"); |
33 | |
34 | URL url = new URL("http://tinybrain.de:8080/tb-int/add_snippet.php"); |
35 | S base = base64encode(data); |
36 | print("Base-encoded => " + l(base)); |
37 | data = null; |
38 | S encoded = new URLCodec().encode(base, "UTF-8"); |
39 | base = null; |
40 | print("URL-encoded => " + l(encoded)); |
41 | String postData = |
42 | "gummipw=" + URLEncoder.encode(unnull(gummipw), "UTF-8") |
43 | + "&blob=" + encoded |
44 | + "&name=" + URLEncoder.encode(unnull(title), "UTF-8") |
45 | + "&type=" + 37 /* SN_DATA */ |
46 | + "&" + (superhigh ? "superhigh" : "high") + "=1&public=1"; |
47 | System.out.println("Post data length: " + postData.length()); |
48 | |
49 | String contents = doPost(postData, url.openConnection(), url); |
50 | System.out.println(contents); |
51 | |
52 | if (isInteger(contents)) { |
53 | long id = parseSnippetID(contents); |
54 | System.out.println("=> #" + id); |
55 | return "#" + id; |
56 | } else |
57 | throw new RuntimeException("Server error: " + contents); |
58 | } |
Began life as a copy of #1000755
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004790 |
Snippet name: | Upload binary data to TinyBrain - use Apache Commons URLEncoder |
Eternal ID of this version: | #1004790/1 |
Text MD5: | 8b6a5419de31b3bc5549578ee8dfcd38 |
Transpilation MD5: | be347855725004f894f3e6232cc02fcd |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-08-31 05:57:39 |
Source code size: | 1908 bytes / 58 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 615 / 699 |
Referenced in: | [show references] |