POST through QNetworkAccessManager slow compared to browser and FTP
-
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
HTTPto upload files to a remotewebserverusing theQNAM->postfunction. My program creates aQhttpmultipartobject and passes that to theQNAM. 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 usingQNAM->post()is about10Mbps. Using POST through Chrome to the same server it's about480Mbps. 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~10Mbpsspeed of theQNAM->postremains 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())); -
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
HTTPto upload files to a remotewebserverusing theQNAM->postfunction. My program creates aQhttpmultipartobject and passes that to theQNAM. 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 usingQNAM->post()is about10Mbps. Using POST through Chrome to the same server it's about480Mbps. 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~10Mbpsspeed of theQNAM->postremains 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()));@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.