Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-135426

[Reg 6.7.3->6.8.2] QHttpPart fails to set Content-Disposition header when using setHeader(QNetworkRequest::ContentDispositionHeader)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P1: Critical
    • None
    • 6.8.2
    • Network: HTTP
    • None
    • OS: macOS 14.6.1 (23G93)
      clang version 19.1.7
      Qt 6.8.2 (broken)
      Qt 6.5.3 (works)
      Qt 6.7.2 (works)
    • macOS

    Description

      Description:

      When using QHttpPart to build multipart/form-data requests, the Content-Disposition header is missing in Qt 6.8.2, while it works correctly in Qt 6.5.3 and 6.7.2. This appears to be a regression introduced in Qt 6.8.2.

       

      Environment:

      OS: macOS 14.6.1 (23G93)

      clang version 19.1.7

      Qt Versions Tested:
      ✅ 6.5.3 (works)
      ✅ 6.7.2 (works)
      ❌ 6.8.2 (broken)

       

      My code:

      void uploadFile(QString user, QString filename, QString md5, int size, QFile* file)
      {
          /* Content-Disposition */
          QHttpPart part;
          QString disp = QString("form-data; "
                                 "user=\"%1\"; "
                                 "filename=\"%2\"; "
                                 "md5=\"%3\"; "
                                 "size=%4")
                             .arg(user, filename, md5, QString::number(size));
          part.setHeader(QNetworkRequest::ContentDispositionHeader, disp);  /// BUG: not work on Qt 6.8.2
      
          /* Content-Type */
          part.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
          part.setBodyDevice(file);
      
          QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
          multiPart->append(part);
          QNetworkRequest request;
          request.setUrl(QString("http://XXXX.XX"));    QNetworkReply* reply = NetworkTool::getNetworkManager()->post(request, multiPart);
          multiPart->setParent(reply);
      
          ...
          /* Send */
          ...
      } 

       

      I tried sending SVG images to the server.

       

      Works in Qt 6.5.3/6.7.2 as shown in sample output below:

      --boundary_.oOo._VwEORf0wIk84+Ljoc7T7mJiPCJnvummn
      Content-Disposition: form-data; user="123123"; filename="histogram.svg"; md5="111111111111"; size=955
      Content-Type: application/octet-stream
      
      <?xml version="1.0" encoding="UTF-8"?>
      <svg width="512" height="512" fill="none" version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
      ...
      </svg>
      
      -{-}boundary_.oOo._VwEORf0wIk84+Ljoc7T7mJiPCJnvummn{-}-
      

       

      But in Qt 6.8.2 the Content-Disposition header is completely missing:

      --boundary_.oOo._NWn8s3zoIDJtwZQtjYDMBG+lVmiu8mBg
      content-type: application/octet-stream
      
      <?xml version="1.0" encoding="UTF-8"?>
      <svg width="512" height="512" fill="none" version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
      ....
      </svg>
      
      -{-}boundary_.oOo._NWn8s3zoIDJtwZQtjYDMBG+lVmiu8mBg{-}-

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            manordheim Mårten Nordheim
            silverfox Jianing Meng
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes