Last active
December 17, 2015 15:39
-
-
Save arifsetiawan/5633624 to your computer and use it in GitHub Desktop.
QMultipart example, express compliant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); | |
QHttpPart textPart; | |
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\"")); | |
textPart.setBody("my text"); | |
QHttpPart imagePart; | |
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png")); | |
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\"; filename=\"image.png\"")); | |
QFile *file = new QFile("image.png"); | |
file->open(QIODevice::ReadOnly); | |
imagePart.setBodyDevice(file); | |
file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart | |
multiPart->append(textPart); | |
multiPart->append(imagePart); | |
QUrl url("http://my.server.tld"); | |
QNetworkRequest request(url); | |
QNetworkAccessManager manager; | |
QNetworkReply *reply = manager.post(request, multiPart); | |
multiPart->setParent(reply); // delete the multiPart with the reply | |
// here connect signals etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment