Nominate our 2022 Qt Champions!

How to upload a break off file?

  • I can upload files with QHttpMultiPart,like sample in qt:
    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/jpeg"));
    imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name="image""));
    QFile *file = new QFile("image.jpg");
    file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart


    QUrl url("http://my.server.tld");
    QNetworkRequest request(url);

    QNetworkAccessManager manager;
    QNetworkReply *reply =, multiPart);
    multiPart->setParent(reply); // delete the multiPart with the reply
    // here connect signals etc.

    And how to upload a break off file, using QHttpMultiPart or other class?
    Thank you.

    [edit: added missing coding tags @ SGaist]

Log in to reply