Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

[[qanda:topic_unsolved]] How to recieve file over QHttpEngine::Server

$
0
0

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;
    }

Viewing all articles
Browse latest Browse all 13965

Trending Articles