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. Uploading files via HTTP/POST using QHttpMultiPart, no longer working
Forum Updated to NodeBB v4.3 + New Features

Uploading files via HTTP/POST using QHttpMultiPart, no longer working

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 3.9k Views 2 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 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()));
    
    1 Reply Last reply
    0
    • G Offline
      G Offline
      GregB
      wrote on last edited by
      #2

      Figured out more details: The problem only occurs on Windows 10, and is not related to the Qt version.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Can you check if that still happens with Qt 5.6 Beta ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

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