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. POST through QNetworkAccessManager slow compared to browser and FTP
Qt 6.11 is out! See what's new in the release blog

POST through QNetworkAccessManager slow compared to browser and FTP

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.1k 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.
  • G Offline
    G Offline
    GregB
    wrote on last edited by
    #1

    I'm reposting this from StackOverflow, as I'm still having this problem and have not seen any changes about it. I noticed that there was a bug report for the exact same issue (https://bugreports.qt.io/browse/QTBUG-22606) but was it closed unresolved as part of Qt4.

    I have an application that uses HTTP to upload files to a remote webserver using the QNAM->post function. My program creates a Qhttpmultipart object and passes that to the QNAM. This all works to upload the files to the webserver just fine. But... it's slow compared to other methods of getting the files to the server. The peak speed using QNAM->post() is about 10Mbps. Using POST through Chrome to the same server it's about 480Mbps. scp and FTP to the same server are equally fast. I've used the program to access other servers and run the program from other networks to different servers. The ~10Mbps speed of the QNAM->post remains the same. What might be going on?

    QStringList md5stringlist;
    /* loop through the list of files */
    ui->progUpload->setRange(0,100);
    for (int i=0;i<list.size();i++) {
        qDebug("UploadFileList [%d] [%s]", i, list[i].toStdString().c_str());
        QFile *file = new QFile(list[i]);
        QHttpPart filePart;
        filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"files[]\"; filename=\""+ file->fileName() + "\""));
        file->open(QIODevice::ReadOnly);
        filePart.setBodyDevice(file);
        //filePart.setBody(file->readAll());
        file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
        multiPart->append(filePart);
        /* create the MD5 list [file|md5,file2|md5,etc] */
        QFileInfo fileInfo(file->fileName());
        QString filename(fileInfo.fileName());
        md5stringlist << md5list[i];
    }
    
    /* add the MD5 list  */
    QString md5string = md5stringlist.join(",");
    /* equipment */
    loginPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"md5list\""));
    loginPart.setBody(md5string.toLatin1());
    multiPart->append(loginPart);
    
    /* check if there was a previous upload still going on */
    while (isUploading) {
        ui->lblStatus->setText("Waiting for previous upload to complete...");
        QTest::qWait(1000);
    }
    
    /* do the POST and setup the event handlers for it */
    QNetworkReply* reply = networkManager->post(request, multiPart);
    multiPart->setParent(reply); // delete the multiPart with the reply
    numNetConn++;
    isUploading = true;
    connect(reply, SIGNAL(finished()), this, SLOT(onGetReplyUpload()));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onNetworkError(QNetworkReply::NetworkError)));
    connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(progressChanged(qint64, qint64)));
    
    WriteLog(QString("Finished queueing %1 files for upload...").arg(list.size()));
    
    raven-worxR 1 Reply Last reply
    0
    • G GregB

      I'm reposting this from StackOverflow, as I'm still having this problem and have not seen any changes about it. I noticed that there was a bug report for the exact same issue (https://bugreports.qt.io/browse/QTBUG-22606) but was it closed unresolved as part of Qt4.

      I have an application that uses HTTP to upload files to a remote webserver using the QNAM->post function. My program creates a Qhttpmultipart object and passes that to the QNAM. This all works to upload the files to the webserver just fine. But... it's slow compared to other methods of getting the files to the server. The peak speed using QNAM->post() is about 10Mbps. Using POST through Chrome to the same server it's about 480Mbps. scp and FTP to the same server are equally fast. I've used the program to access other servers and run the program from other networks to different servers. The ~10Mbps speed of the QNAM->post remains the same. What might be going on?

      QStringList md5stringlist;
      /* loop through the list of files */
      ui->progUpload->setRange(0,100);
      for (int i=0;i<list.size();i++) {
          qDebug("UploadFileList [%d] [%s]", i, list[i].toStdString().c_str());
          QFile *file = new QFile(list[i]);
          QHttpPart filePart;
          filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"files[]\"; filename=\""+ file->fileName() + "\""));
          file->open(QIODevice::ReadOnly);
          filePart.setBodyDevice(file);
          //filePart.setBody(file->readAll());
          file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
          multiPart->append(filePart);
          /* create the MD5 list [file|md5,file2|md5,etc] */
          QFileInfo fileInfo(file->fileName());
          QString filename(fileInfo.fileName());
          md5stringlist << md5list[i];
      }
      
      /* add the MD5 list  */
      QString md5string = md5stringlist.join(",");
      /* equipment */
      loginPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"md5list\""));
      loginPart.setBody(md5string.toLatin1());
      multiPart->append(loginPart);
      
      /* check if there was a previous upload still going on */
      while (isUploading) {
          ui->lblStatus->setText("Waiting for previous upload to complete...");
          QTest::qWait(1000);
      }
      
      /* do the POST and setup the event handlers for it */
      QNetworkReply* reply = networkManager->post(request, multiPart);
      multiPart->setParent(reply); // delete the multiPart with the reply
      numNetConn++;
      isUploading = true;
      connect(reply, SIGNAL(finished()), this, SLOT(onGetReplyUpload()));
      connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onNetworkError(QNetworkReply::NetworkError)));
      connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(progressChanged(qint64, qint64)));
      
      WriteLog(QString("Finished queueing %1 files for upload...").arg(list.size()));
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @GregB said in POST through QNetworkAccessManager slow compared to browser and FTP:

      I noticed that there was a bug report for the exact same issue (https://bugreports.qt.io/browse/QTBUG-22606) but was it closed unresolved as part of Qt4.

      you can request an reopening of the bug for Qt5 as the comment states
      But i guess it wont be fixed any time soon.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2

      • Login

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