Important: Please read the Qt Code of Conduct -

How to send photo on telegram bot whit QHttpMultiPart

  • Hi
    I want to send a photo to telegram bot with multipart
    this is telegram bot api about Send file
    how can i send photo to telegram bot in Qt

    As far as I know I should use QHttpMultiPart
    Please show me a example

  • Hi!

    QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
    QHttpPart textPart;
    textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\""));
    textPart.setBody("my text");
    QHttpPart imagePart;
    imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
    imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\""));
    QFile *file = new QFile("image.jpg");
    file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
    QUrl url("http://my.server.tld");
    QNetworkRequest request(url);
    QNetworkAccessManager manager;
    QNetworkReply *reply =, multiPart);
    multiPart->setParent(reply); // delete the multiPart with the reply
    // here connect signals etc.

    See: QHttpMultiPart Class

  • @Wieland I saw this before but i know how work, like 'setHeader' & 'setBody' what is that?

  • The header and body are part of the HTTP request you want to send.

  • @Wieland for send a photo to telegram bot i should do this :

    reply = manager->get(QNetworkRequest(QUrl("" +Token + "/sendPhoto?chat_id=" + chatID  + "&photo=" + photo + "&disable_notification=" + disableNotificationText)));

    but in QHttpMultiPart i dont know how to do this

  • Any one can help me

    how to do this in QHttpMultiPart :

    reply = manager->get(QNetworkRequest(QUrl("" +Token + "/sendPhoto?chat_id=" + chatID  + "&photo=" + photo + "&disable_notification=" + disableNotificationText)));

Log in to reply