Unsolved Uploading files via HTTP/POST using QHttpMultiPart, no longer working
-
I have an application that uploads files to an http server. The application was working correctly until I upgraded the Qt version from 5.5.0 to 5.5.1.
Basically, after doing the networkmanager->post() operation, it never receives signals (finished, error, uploadprogress). So my application just waits for the signals which never come.
I have other form submission in my application which doesn't submit files, but those work just fine. I submit the form, and either the finished or error signals get called.
This is the abbreviated code for my file upload, which used to work, but now doesn't
QUrl url(connServer + "/api.php"); QNetworkRequest request(url); QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart loginPart; /* username */ loginPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"u\"")); loginPart.setBody(connUsername.toLatin1()); multiPart->append(loginPart); /* password */ loginPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"p\"")); loginPart.setBody(connPassword.toLatin1()); multiPart->append(loginPart); /* loop through the list of files */ ui->progUpload->setRange(0,100); for (int i=0;i<list.size();i++) { 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); file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart multiPart->append(filePart); } while (isUploading) { ui->lblStatus->setText("Waiting for response from server"); QTest::qWait(1000); } QNetworkReply* reply = networkManager->post(request, multiPart); multiPart->setParent(reply); // delete the multiPart with the reply 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)));
This doesn't submit files with the form, and it still works fine:
QUrl url(connServer + "/api.php"); QNetworkRequest request(url); QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart loginPart; /* username */ loginPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"u\"")); loginPart.setBody(connUsername.toLatin1()); multiPart->append(loginPart); /* password */ loginPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"p\"")); loginPart.setBody(connPassword.toLatin1()); multiPart->append(loginPart); /* action */ loginPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"action\"")); loginPart.setBody("startTransaction"); multiPart->append(loginPart); QNetworkReply* reply = networkManager->post(request, multiPart); multiPart->setParent(reply); // delete the multiPart with the reply connect(reply, SIGNAL(finished()), this, SLOT(onGetReplyStartTransaction()));
-
Figured out more details: The problem only occurs on Windows 10, and is not related to the Qt version.
-
Hi and welcome to devnet,
Can you check if that still happens with Qt 5.6 Beta ?