Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

InvalidArgument: POST requires exacty one file upload per request



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

    <Error>
    <Code>InvalidArgument</Code>
    <Message>POST requires exactly one file upload per request.</Message>
    <ArgumentValue>0</ArgumentValue>
    <ArgumentName>file</ArgumentName>
    </Error>

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

    QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
    file->setParent(multiPart);
    multiPart->append(filePart);

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

    Do you have any advice?

    Thanks



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

    I have a note in "QNetworkAccessManager":http://qt-project.org/doc/qt-4.8/qnetworkaccessmanager.html entitled "POST with QIODevice" , you might find it useful.

    If you are trying to "upload" using a Form, use "FormPost":http://www.tuckdesign.com/sources/Qt , it saved me a lot of time when I was coding for "libqsendspace":https://github.com/Code-ReaQtor/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