Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to send photo on telegram bot whit QHttpMultiPart
Forum Updated to NodeBB v4.3 + New Features

How to send photo on telegram bot whit QHttpMultiPart

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ars2772
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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->open(QIODevice::ReadOnly);
      imagePart.setBodyDevice(file);
      file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
      
      multiPart->append(textPart);
      multiPart->append(imagePart);
      
      QUrl url("http://my.server.tld");
      QNetworkRequest request(url);
      
      QNetworkAccessManager manager;
      QNetworkReply *reply = manager.post(request, multiPart);
      multiPart->setParent(reply); // delete the multiPart with the reply
      // here connect signals etc.
      

      See: QHttpMultiPart Class

      A 1 Reply Last reply
      1
      • ? A Former User

        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->open(QIODevice::ReadOnly);
        imagePart.setBodyDevice(file);
        file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
        
        multiPart->append(textPart);
        multiPart->append(imagePart);
        
        QUrl url("http://my.server.tld");
        QNetworkRequest request(url);
        
        QNetworkAccessManager manager;
        QNetworkReply *reply = manager.post(request, multiPart);
        multiPart->setParent(reply); // delete the multiPart with the reply
        // here connect signals etc.
        

        See: QHttpMultiPart Class

        A Offline
        A Offline
        ars2772
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

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

          A 1 Reply Last reply
          1
          • ? A Former User

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

            A Offline
            A Offline
            ars2772
            wrote on last edited by ars2772
            #5

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

            reply = manager->get(QNetworkRequest(QUrl("https://api.telegram.org/bot" +Token + "/sendPhoto?chat_id=" + chatID  + "&photo=" + photo + "&disable_notification=" + disableNotificationText)));
            

            but in QHttpMultiPart i dont know how to do this

            1 Reply Last reply
            0
            • A Offline
              A Offline
              ars2772
              wrote on last edited by ars2772
              #6

              Any one can help me

              how to do this in QHttpMultiPart :

              reply = manager->get(QNetworkRequest(QUrl("https://api.telegram.org/bot" +Token + "/sendPhoto?chat_id=" + chatID  + "&photo=" + photo + "&disable_notification=" + disableNotificationText)));
              
              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved