How to receive file over QHttpEngine::Server
Unsolved
QtWebEngine
-
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; }
-
@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();