ZaharL
5/4/2019 - 6:46 PM

Telegram file uploading

Telegram file uploading

private void uploadRouteFileToTelegramBot(Consumer<Boolean> completed, Boolean success) {
        File file = new File(context.getExternalFilesDir(null), "eda_driver");
        File gpxfile = new File(file, GpsDistanceService.ROUTE_FILE_NAME);
        RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), gpxfile);
        MultipartBody.Part body = MultipartBody.Part.createFormData("document", gpxfile.getName(), requestFile);
        Call<ResponseBody> objectCall = telegramApi.sendFileToTelegramBot(TELEGRAM_CHAT_ID, body);
        objectCall.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                Object body1 = response.body();
                response.toString();
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                t.toString();
            }
        });
    }
public interface TelegramApi {
    @Multipart
    @POST("sendDocument")
    Call<ResponseBody> sendFileToTelegramBot(@Query("chat_id") String header,
                                             @Part MultipartBody.Part body);
}