Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to receive file over QHttpEngine::Server

    QtWebEngine
    2
    4
    401
    Loading More Posts
    • 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.
    • N
      Nanda1605 last edited by aha_1980

      Hi,
      I am developing a module, in which i have to recieve the file over HTTP from client.

      I used Swagger and openAPI generator to create classes and cmake file. Below is the section where i have to handle the file. This module is a server and it has to recieve/download the file from client

      How to read/download the file ?

      PS: Using postman to upload the file (as form-data).

      void OAIPkgupdaterApiRequest::pkgupdaterUpdatePostRequest(){
          qDebug() << "/v1/pkgupdater/update";
          connect(this, &OAIPkgupdaterApiRequest::pkgupdaterUpdatePost, handler.data(), &OAIPkgupdaterApiHandler::pkgupdaterUpdatePost);
      
          OAIHttpFileElement uploadfile;
          QString imagename;
          QString key;
          QString overwrite;
      
          emit pkgupdaterUpdatePost(uploadfile, imagename, key, overwrite);
      }
      
      

      Below snippet from Main function

          // Obtain the values
          QHostAddress address = QHostAddress(parser.value(addressOption));
          quint16 port = static_cast<quint16>(parser.value(portOption).toInt());
      
          QSharedPointer<OpenAPI::OAIApiRequestHandler> handler(new OpenAPI::OAIApiRequestHandler());
          auto router = QSharedPointer<OpenAPI::OAIApiRouter>::create();
          router->setUpRoutes();
          QObject::connect(handler.data(), &OpenAPI::OAIApiRequestHandler::requestReceived, [&](QHttpEngine::Socket *socket) {
              router->processRequest(socket);
          });
      
          QHttpEngine::Server server(handler.data());
          qDebug() << "Serving on " << address.toString() << ":" << port;
          // Attempt to listen on the specified port
          if (!server.listen(address, port)) {
              qCritical("Unable to listen on the specified port.");
              return 1;
          }
      
      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        Do you receive all the data in one go ?
        If so, I would say use QFile to write the content of the file to disk.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        N 1 Reply Last reply Reply Quote 0
        • N
          Nanda1605 @SGaist last edited by

          @SGaist Thanks for your reply.

          If i pass JSON objects in the postman Body i could see the attributes with the below set of codes. I am aware how to read the file or download the file in the server end. I belive QFile is to handle the local file, i am looking for the file handling over http

          QJsonDocument doc 
          socket->readJson(doc);
          QJsonObject obj = doc.object();
          
          
          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Well, server side, you will have to save your file at some point. That's when QFile comes handy.

            Just in case, you might want to check the Cutelyst project.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post