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

QOAuth2AuthorizationCodeFlow and Multipart file upload

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.12.8
    • None
    • All

    Description

      I have a QOAuth2AuthorizationCodeFlow (this->m_auth) and i want to use it to upload a file usingĀ  a multipart/form-data HTTPS POST request.

      Here is the important part of the call:

      void MyClass::post_file_to_api(QUrl url, QFile* file, CallbackFunc callback){
      QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::ContentType::FormDataType, this);
      QHttpPart part;
      if(!file->open(QIODevice::ReadOnly)) { delete file; return; }
      
      part.setBodyDevice(file); file->setParent(multiPart);
      multiPart->append(part); multiPart->setContentType(QHttpMultiPart::ContentType::FormDataType); QNetworkReply* reply = this->m_auth->post(url, multiPart); this->connectCallback( reply, callback );
      
      return;
      } 

      Other authenticated requests to the API work as expected, but this does not set the ContentType of the Request to "multipart/form-data" as promised by the documentation:

      https://doc.qt.io/qt-5/qhttpmultipart.html#setContentType

      https://doc.qt.io/qt-5/qhttpmultipart.html#ContentType-enum

      The Captured HTTP Stream looks like this:
      It can be seen, that the Content-Type is set to "application/x-www-form-urlencoded" which does confuse my backend.It looks like the QHttpMultipart::ContentType is somehow interpreted like a QAbstractOAuth::ContentType

      Attachments

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

        Activity

          People

            vuokko Juha Vuolle
            ygerlach Yannis Gerlach
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes