QHttpMultiPart not setting headers correctly
Solved
General and Desktop
-
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 -
It seems like I needed to manually add:
QByteArray boundary = bookCover->boundary(); request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=" + boundary);
Now
-