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. QHttpMultiPart not setting headers correctly
Qt 6.11 is out! See what's new in the release blog

QHttpMultiPart not setting headers correctly

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 207 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.
  • C Offline
    C Offline
    Creaperdown
    wrote on last edited by
    #1

    Hey, I am in the process of upgrading to Qt6, but for some reason my QHttpMultipart code does not set the correct headers anymore. I have this simple MultiPart upload:
    auto bookCover = new QHttpMultiPart(QHttpMultiPart::FormDataType);
    QString stringUuid = uuid.toString(QUuid::WithoutBraces);

    QFile* file = new QFile(QUrl(path).path());
    // openfile ...
    
    QHttpPart imagePart;
    imagePart.setHeader(QNetworkRequest::ContentTypeHeader,
                        QVariant("image/png"));
    imagePart.setHeader(QNetworkRequest::ContentDispositionHeader,
                        QVariant("form-data; name=\"image\"; filename=\"" +
                                 file->fileName() + "\""));
    imagePart.setBodyDevice(file);
    bookCover->append(imagePart);
    
    
    QUrl endpoint = data::changeBookCoverEndpoint + "/" + stringUuid;
    auto request = createRequest(endpoint, authToken);
    
    auto reply = m_networkAccessManager.post(request, bookCover);
    

    But the ContentType that is sent is "application/json" instead of "multipart/form-data" and the content-type boundary isn't set anymore either.
    This worked just fine with Qt 5

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Creaperdown
      wrote on last edited by
      #2

      It seems like I needed to manually add:

      QByteArray boundary = bookCover->boundary();
          request.setHeader(QNetworkRequest::ContentTypeHeader,
                            "multipart/form-data; boundary=" + boundary);
      

      Now

      1 Reply Last reply
      0
      • C Creaperdown has marked this topic as solved on

      • Login

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