Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Using QHttpMultipart for a HTML form
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Using QHttpMultipart for a HTML form

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Code_ReaQtor
    wrote on last edited by
    #1

    Greetings!

    I got a problem with QNetworkAccessmanager::post() method in uploading a file programmatically using QHttpMultipart.

    I got success using an HTML form via QWebView. The HTML form looks like this:

    @<form method="post" action="[url value received in response]" enctype="multipart/form-data">
    <!-- MUST FIELDS -->
    <input type="hidden" name="MAX_FILE_SIZE" value="[max_file_size value received in response]">
    <input type="hidden" name="UPLOAD_IDENTIFIER" value="[upload_identifier value received in response]">
    <input type="hidden" name="extra_info" value="[extra_info value received in response]">
    <input type="file" name="userfile">
    <input type="submit" value="Submit">
    </form>@

    It doesn't help a lot since I need to select a file (without user interaction) and submit it to a certain url. I followed the guide in the QHttpmultipart documentation but "fails" every-time.

    Please visit my open-source projects at https://github.com/Code-ReaQtor.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Code_ReaQtor
      wrote on last edited by
      #2

      I already solved it. Seems like there is something wrong with the documentation for QHttpMultiPart. The documentation points out RFC 2046 but can't find the answer as I search for it.

      I was able to google RFC 1867 which solved the problem.

      In the documentation:
      @QHttpPart imagePart;
      imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
      imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name="image""));@

      I think the problem was that ContentDispositionHeader should come first before ContentTypeHeader.
      I tried this using the "file" input control and not with an "image" as cited in the code;

      Please visit my open-source projects at https://github.com/Code-ReaQtor.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Code_ReaQtor
        wrote on last edited by
        #3

        Seems like my method is too buggy. Sometimes it uploads a file and sometimes it doesn't.... I don't know why.

        Well, I found a solution from "TuckDesgin":http://www.tuckdesign.com/sources/Qt and modified it.

        ... and it worked for me everytime, I just need to test it again and again just to make sure.

        Please visit my open-source projects at https://github.com/Code-ReaQtor.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dv879
          wrote on last edited by
          #4

          Thank you Code_ReaQtor for sharing the link to TuckDesign's solution. It really does the trick! :)

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Code_ReaQtor
            wrote on last edited by
            #5

            [quote author="dv879" date="1361446791"]Thank you Code_ReaQtor for sharing the link to TuckDesign's solution. It really does the trick! :)[/quote]

            Sure. You're welcome.

            Please visit my open-source projects at https://github.com/Code-ReaQtor.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved