InvalidArgument: POST requires exacty one file upload per request

  • I try to use QHttpMultiPart to post a file but there is a following errr:

    <Message>POST requires exactly one file upload per request.</Message>

    The following are my codes:
    QFile *file = new QFile(filePath);
    QHttpPart filePart;
    filePart.setHeader(QNetworkRequest::ContentTypeHeader, typeHeader);
    filePart.setHeader(QNetworkRequest::ContentDispositionHeader, upload_content_disposition);
    filePart.setRawHeader("FileName", fileName);
    filePart.setRawHeader("file", filePath);

    QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

    QNetworkRequest request(qurl);
    mQTManager->post(request, multiPart);

    Do you have any advice?


  • QHttpMultipart is very buggy and I think it uses a very different specification so it always fail.

    I have a note in "QNetworkAccessManager": entitled "POST with QIODevice" , you might find it useful.

    If you are trying to "upload" using a Form, use "FormPost": , it saved me a lot of time when I was coding for "libqsendspace": . You just need to modify their source code or you may use the code from my github site ("qsendspace" folder).

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.