Change MultipartEntityBuilder.addBinaryBody() function

This commit is contained in:
antonu17 2016-06-03 23:22:13 +06:00
parent ee12175eea
commit 7b6a376976

View File

@ -502,7 +502,7 @@ public abstract class AbsSender {
if (sendDocument.isNewDocument()) { if (sendDocument.isNewDocument()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendDocument.CHATID_FIELD, sendDocument.getChatId()); builder.addTextBody(SendDocument.CHATID_FIELD, sendDocument.getChatId());
builder.addBinaryBody(SendDocument.DOCUMENT_FIELD, new java.io.File(sendDocument.getDocument()), ContentType.APPLICATION_OCTET_STREAM, sendDocument.getDocumentName()); builder.addBinaryBody(SendDocument.DOCUMENT_FIELD, sendDocument.getNewDocumentFile());
if (sendDocument.getReplayMarkup() != null) { if (sendDocument.getReplayMarkup() != null) {
builder.addTextBody(SendDocument.REPLYMARKUP_FIELD, sendDocument.getReplayMarkup().toJson().toString()); builder.addTextBody(SendDocument.REPLYMARKUP_FIELD, sendDocument.getReplayMarkup().toJson().toString());
} }
@ -562,7 +562,7 @@ public abstract class AbsSender {
if (sendPhoto.isNewPhoto()) { if (sendPhoto.isNewPhoto()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendPhoto.CHATID_FIELD, sendPhoto.getChatId()); builder.addTextBody(SendPhoto.CHATID_FIELD, sendPhoto.getChatId());
builder.addBinaryBody(SendPhoto.PHOTO_FIELD, new java.io.File(sendPhoto.getPhoto()), ContentType.APPLICATION_OCTET_STREAM, sendPhoto.getPhotoName()); builder.addBinaryBody(SendPhoto.PHOTO_FIELD, sendPhoto.getNewPhotoFile());
if (sendPhoto.getReplayMarkup() != null) { if (sendPhoto.getReplayMarkup() != null) {
builder.addTextBody(SendPhoto.REPLYMARKUP_FIELD, sendPhoto.getReplayMarkup().toJson().toString()); builder.addTextBody(SendPhoto.REPLYMARKUP_FIELD, sendPhoto.getReplayMarkup().toJson().toString());
} }
@ -622,7 +622,7 @@ public abstract class AbsSender {
if (sendVideo.isNewVideo()) { if (sendVideo.isNewVideo()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendVideo.CHATID_FIELD, sendVideo.getChatId()); builder.addTextBody(SendVideo.CHATID_FIELD, sendVideo.getChatId());
builder.addBinaryBody(SendVideo.VIDEO_FIELD, new java.io.File(sendVideo.getVideo()), ContentType.APPLICATION_OCTET_STREAM, sendVideo.getVideoName()); builder.addBinaryBody(SendVideo.VIDEO_FIELD, sendVideo.getNewVideoFile());
if (sendVideo.getReplayMarkup() != null) { if (sendVideo.getReplayMarkup() != null) {
builder.addTextBody(SendVideo.REPLYMARKUP_FIELD, sendVideo.getReplayMarkup().toJson().toString()); builder.addTextBody(SendVideo.REPLYMARKUP_FIELD, sendVideo.getReplayMarkup().toJson().toString());
} }
@ -701,7 +701,7 @@ public abstract class AbsSender {
if (sendSticker.isNewSticker()) { if (sendSticker.isNewSticker()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendSticker.CHATID_FIELD, sendSticker.getChatId()); builder.addTextBody(SendSticker.CHATID_FIELD, sendSticker.getChatId());
builder.addBinaryBody(SendSticker.STICKER_FIELD, new java.io.File(sendSticker.getSticker()), ContentType.APPLICATION_OCTET_STREAM, sendSticker.getStickerName()); builder.addBinaryBody(SendSticker.STICKER_FIELD, sendSticker.getNewStickerFile());
if (sendSticker.getReplayMarkup() != null) { if (sendSticker.getReplayMarkup() != null) {
builder.addTextBody(SendSticker.REPLYMARKUP_FIELD, sendSticker.getReplayMarkup().toJson().toString()); builder.addTextBody(SendSticker.REPLYMARKUP_FIELD, sendSticker.getReplayMarkup().toJson().toString());
} }
@ -763,7 +763,7 @@ public abstract class AbsSender {
if (sendAudio.isNewAudio()) { if (sendAudio.isNewAudio()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendAudio.CHATID_FIELD, sendAudio.getChatId()); builder.addTextBody(SendAudio.CHATID_FIELD, sendAudio.getChatId());
builder.addBinaryBody(SendAudio.AUDIO_FIELD, new java.io.File(sendAudio.getAudio()), ContentType.create("audio/mpeg"), sendAudio.getAudioName()); builder.addBinaryBody(SendAudio.AUDIO_FIELD, sendAudio.getNewAudioFile());
if (sendAudio.getReplayMarkup() != null) { if (sendAudio.getReplayMarkup() != null) {
builder.addTextBody(SendAudio.REPLYMARKUP_FIELD, sendAudio.getReplayMarkup().toJson().toString()); builder.addTextBody(SendAudio.REPLYMARKUP_FIELD, sendAudio.getReplayMarkup().toJson().toString());
} }
@ -831,6 +831,7 @@ public abstract class AbsSender {
/** /**
* Sends a voice note using Send Voice method (https://core.telegram.org/bots/api#sendvoice) * Sends a voice note using Send Voice method (https://core.telegram.org/bots/api#sendvoice)
* For this to work, your audio must be in an .ogg file encoded with OPUS
* @param sendVoice Information to send * @param sendVoice Information to send
* @return If success, the sent Message is returned * @return If success, the sent Message is returned
* @throws TelegramApiException If there is any error sending the audio * @throws TelegramApiException If there is any error sending the audio
@ -845,7 +846,7 @@ public abstract class AbsSender {
if (sendVoice.isNewVoice()) { if (sendVoice.isNewVoice()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendVoice.CHATID_FIELD, sendVoice.getChatId()); builder.addTextBody(SendVoice.CHATID_FIELD, sendVoice.getChatId());
builder.addBinaryBody(SendVoice.AUDIO_FIELD, new java.io.File(sendVoice.getAudio()), ContentType.create("audio/ogg"), sendVoice.getVoiceName()); builder.addBinaryBody(SendVoice.AUDIO_FIELD, sendVoice.getNewVoiceFile());
if (sendVoice.getReplayMarkup() != null) { if (sendVoice.getReplayMarkup() != null) {
builder.addTextBody(SendVoice.REPLYMARKUP_FIELD, sendVoice.getReplayMarkup().toJson().toString()); builder.addTextBody(SendVoice.REPLYMARKUP_FIELD, sendVoice.getReplayMarkup().toJson().toString());
} }