Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void hostFileOnline(InputStream attachment, Consumer<String> callback) {
- try {
- String text = IOUtils.toString(attachment, StandardCharsets.UTF_8.name());
- Request request = WebUtils.defaultRequest().post(RequestBody.create(null, text.getBytes()))
- .url(PASTE_SERVER + "documents").addHeader("Content-Type", ContentType.TEXT_HTML.getType()).build();
- WebUtils.ins.prepareRaw(request, (result) -> WebParserUtils.toJSONObject(result, new ObjectMapper()))
- .async((json) -> {
- String key = json.get("key").asText();
- System.out.println("KEY: " + key);
- callback.accept(PASTE_SERVER + key);
- }, (error) -> {
- error.printStackTrace();
- callback.accept("Error: " + error.getMessage());
- });
- } catch (IOException e) {
- throw new IllegalArgumentException(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment