TurtyWurty

Untitled

Mar 13th, 2021
1,283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1.     private void hostFileOnline(InputStream attachment, Consumer<String> callback) {
  2.         try {
  3.             String text = IOUtils.toString(attachment, StandardCharsets.UTF_8.name());
  4.             Request request = WebUtils.defaultRequest().post(RequestBody.create(null, text.getBytes()))
  5.                     .url(PASTE_SERVER + "documents").addHeader("Content-Type", ContentType.TEXT_HTML.getType()).build();
  6.  
  7.             WebUtils.ins.prepareRaw(request, (result) -> WebParserUtils.toJSONObject(result, new ObjectMapper()))
  8.                     .async((json) -> {
  9.                         String key = json.get("key").asText();
  10.                         System.out.println("KEY: " + key);
  11.                         callback.accept(PASTE_SERVER + key);
  12.                     }, (error) -> {
  13.                         error.printStackTrace();
  14.                         callback.accept("Error: " + error.getMessage());
  15.                     });
  16.         } catch (IOException e) {
  17.             throw new IllegalArgumentException(e);
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment