use of com.mashape.unirest.request.body.MultipartBody in project Javacord by BtoBastian.
the class ImplUser method sendFile.
@Override
public Future<Message> sendFile(final InputStream inputStream, final String filename, final String comment, FutureCallback<Message> callback) {
final MessageReceiver receiver = this;
ListenableFuture<Message> future = api.getThreadPool().getListeningExecutorService().submit(new Callable<Message>() {
@Override
public Message call() throws Exception {
logger.debug("Trying to send an input stream to user {} (comment: {})", ImplUser.this, comment);
api.checkRateLimit(null, RateLimitType.PRIVATE_MESSAGE, null, null);
MultipartBody body = Unirest.post("https://discordapp.com/api/v6/channels/" + getUserChannelIdBlocking() + "/messages").header("authorization", api.getToken()).field("file", inputStream, filename);
if (comment != null) {
body.field("content", comment);
}
HttpResponse<JsonNode> response = body.asJson();
api.checkResponse(response);
api.checkRateLimit(response, RateLimitType.PRIVATE_MESSAGE, null, null);
logger.debug("Sent an input stream to user {} (comment: {})", ImplUser.this, comment);
return new ImplMessage(response.getBody().getObject(), api, receiver);
}
});
if (callback != null) {
Futures.addCallback(future, callback);
}
return future;
}
Aggregations