Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. How to receive file over QHttpEngine::Server
QtWS25 Last Chance

How to receive file over QHttpEngine::Server

Scheduled Pinned Locked Moved Unsolved QtWebEngine
4 Posts 2 Posters 684 Views
  • 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 Offline
    N Offline
    Nanda1605
    wrote on last edited by aha_1980
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • SGaistS SGaist

        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.

        N Offline
        N Offline
        Nanda1605
        wrote on last edited by
        #3

        @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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

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