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. Post upload file send only 16kb
Qt 6.11 is out! See what's new in the release blog

Post upload file send only 16kb

Scheduled Pinned Locked Moved Unsolved General and Desktop
25 Posts 5 Posters 3.5k Views 3 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.
  • V vicsoftware

    @JonB When i should close file? After post statement?

    QTWindow is simple QMainWindow class.

    Updated

    m_requestReply = { m_netManager->post( request, m_requestFile ) };
    m_requestFile->close();
    
    Upload...
    Upload success.
    QIODevice::read (QFile, "/home/vsw/test2.jpg"): device not open
    Upload error code: 99
    0 0
    Upload finished.
    Upload error: Unknown error
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #7

    @vicsoftware said in Post upload file send only 16kb:

    @JonB When i should close file? After post statement?

    data must be open for reading and must remain valid until the finished() signal is emitted for this reply.

    So in onRequestFinished you need to close it, and (presumably) delete m_requestFile. You also need that done in the error case (assuming that does not generate a QNetworkReply::finished).

    In that light, your placement of m_requestFile->close(); above is wrong now and will cause the device not open, get that fixed and try again.

    V 1 Reply Last reply
    1
    • JonBJ JonB

      @vicsoftware said in Post upload file send only 16kb:

      @JonB When i should close file? After post statement?

      data must be open for reading and must remain valid until the finished() signal is emitted for this reply.

      So in onRequestFinished you need to close it, and (presumably) delete m_requestFile. You also need that done in the error case (assuming that does not generate a QNetworkReply::finished).

      In that light, your placement of m_requestFile->close(); above is wrong now and will cause the device not open, get that fixed and try again.

      V Offline
      V Offline
      vicsoftware
      wrote on last edited by vicsoftware
      #8

      @JonB Tried close file and close reply:

      void QTWindow::onRequestFinished( QNetworkReply * reply )
      {
          reply->close();
          reply->deleteLater();
      //    m_requestFile->close();
      //    delete m_requestFile;
          log( "Upload finished." );
      }
      

      Same issue.

      As i see finished does not fired. It waits some responce or somthing else.

      Upload...
      Upload success.
      16384 27025
      16384 27025

      JonBJ 1 Reply Last reply
      0
      • V vicsoftware

        @JonB Tried close file and close reply:

        void QTWindow::onRequestFinished( QNetworkReply * reply )
        {
            reply->close();
            reply->deleteLater();
        //    m_requestFile->close();
        //    delete m_requestFile;
            log( "Upload finished." );
        }
        

        Same issue.

        As i see finished does not fired. It waits some responce or somthing else.

        Upload...
        Upload success.
        16384 27025
        16384 27025

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #9

        @vicsoftware
        To be clear: I only put those remarks in for your good coding behaviour (hence the "And just BTW:"). They were not expected to have any effect on whatever your upload problem is.

        V 1 Reply Last reply
        0
        • JonBJ JonB

          @vicsoftware
          To be clear: I only put those remarks in for your good coding behaviour (hence the "And just BTW:"). They were not expected to have any effect on whatever your upload problem is.

          V Offline
          V Offline
          vicsoftware
          wrote on last edited by vicsoftware
          #10

          @JonB Yes, i simply try all advises, cause i fight with this second day. Read all forums and decided to write here.
          I can take any other c++ library, but should understand it.

          First i tried Multipart https://doc.qt.io/qt-5/qhttpmultipart.html
          Issue exactly the same.
          But python and curl works on my pc and other person.

          JonBJ 1 Reply Last reply
          0
          • V vicsoftware

            @JonB Yes, i simply try all advises, cause i fight with this second day. Read all forums and decided to write here.
            I can take any other c++ library, but should understand it.

            First i tried Multipart https://doc.qt.io/qt-5/qhttpmultipart.html
            Issue exactly the same.
            But python and curl works on my pc and other person.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #11

            @vicsoftware
            I haven't Googled, but if I were in your position I would go find the simplest example of a file upload example out there for Qt. There must be many, maybe even on the docs page, there are also probably answers with it on this forum. Try the standard code others use and see if that works on bigger file.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #12

              Hi,

              Did you also check that your headers are all correct ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              V 1 Reply Last reply
              0
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #13

                Check for limits on the server you are posting to. Does other software allow you to post bigger files? We have a server we wrote in python that had a limit of 40MB. It was a self imposed limit.

                C++ is a perfectly valid school of magic.

                V 1 Reply Last reply
                0
                • fcarneyF fcarney

                  Check for limits on the server you are posting to. Does other software allow you to post bigger files? We have a server we wrote in python that had a limit of 40MB. It was a self imposed limit.

                  V Offline
                  V Offline
                  vicsoftware
                  wrote on last edited by
                  #14

                  @fcarney Any files with any libraries. But not Qt. May be it is bug?

                  1 Reply Last reply
                  0
                  • fcarneyF Offline
                    fcarneyF Offline
                    fcarney
                    wrote on last edited by
                    #15

                    Looks like some sort of config limit:
                    https://doc.qt.io/qt-5/qnetworkrequest.html#http2Configuration

                    C++ is a perfectly valid school of magic.

                    V 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Hi,

                      Did you also check that your headers are all correct ?

                      V Offline
                      V Offline
                      vicsoftware
                      wrote on last edited by vicsoftware
                      #16

                      @SGaist I think yes. I tried many combinations. I compare headers from curl and python requests and they works. May be Qt network engine needs additional headers, but it is abnormal.

                      Now it works with curl cpp wrapper in same class in same function without any problems.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        Did you try following the example of QHttpMultiPart ? Adding only the minimal set of headers like the authentication and nothing else ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        V 1 Reply Last reply
                        0
                        • fcarneyF fcarney

                          Looks like some sort of config limit:
                          https://doc.qt.io/qt-5/qnetworkrequest.html#http2Configuration

                          V Offline
                          V Offline
                          vicsoftware
                          wrote on last edited by vicsoftware
                          #18

                          @fcarney Tried:

                          QHttp2Configuration conf = request.http2Configuration();
                          conf.setMaxFrameSize( 100 * 1024 * 1024 );
                          request.setHttp2Configuration( conf );
                          

                          And got this:

                          Upload...
                          qt.network.http2: Maximum frame size to advertise is invalid
                          Upload success.
                          16384 27025
                          16384 27025
                          27025 27025
                          0 0
                          Upload finished.
                          
                          10 Mb file
                          
                          Upload...
                          qt.network.http2: Maximum frame size to advertise is invalid
                          Upload success.
                          16384 10669810
                          16384 10669810
                          16384 10669810
                          16384 10669810
                          Upload error code: 2
                          0 0
                          Upload finished.
                          Upload error: Connection closed
                          
                          

                          It is something new.

                          And it is also very slow.

                          1 Reply Last reply
                          0
                          • SGaistS SGaist

                            Did you try following the example of QHttpMultiPart ? Adding only the minimal set of headers like the authentication and nothing else ?

                            V Offline
                            V Offline
                            vicsoftware
                            wrote on last edited by
                            #19

                            @SGaist Yes, i did all Googled combinations to upload file via QT nm.post, including qtmultipart examples from stackoverflow. Always failed.

                            1 Reply Last reply
                            0
                            • fcarneyF Offline
                              fcarneyF Offline
                              fcarney
                              wrote on last edited by
                              #20

                              I just looked at some code we use. It uses multipart and we can send files larger than 16KB. I cannot share it though.

                              C++ is a perfectly valid school of magic.

                              V 1 Reply Last reply
                              0
                              • fcarneyF Offline
                                fcarneyF Offline
                                fcarney
                                wrote on last edited by
                                #21

                                Also, for size we use QVariant(device->size()) in the content header content length. Not sure if that would make a difference. I believe size is an integer of some type.

                                C++ is a perfectly valid school of magic.

                                V 1 Reply Last reply
                                0
                                • fcarneyF fcarney

                                  Also, for size we use QVariant(device->size()) in the content header content length. Not sure if that would make a difference. I believe size is an integer of some type.

                                  V Offline
                                  V Offline
                                  vicsoftware
                                  wrote on last edited by vicsoftware
                                  #22

                                  @fcarney Tried that:

                                  request.setHeader( QNetworkRequest::ContentLengthHeader, QVariant{ m_requestFile->size() } );
                                  request.setHeader( QNetworkRequest::ContentTypeHeader, QVariant{ "image/jpeg" } );
                                  

                                  Same bug.

                                  May be QT developers can help?

                                  fcarneyF 1 Reply Last reply
                                  0
                                  • fcarneyF fcarney

                                    I just looked at some code we use. It uses multipart and we can send files larger than 16KB. I cannot share it though.

                                    V Offline
                                    V Offline
                                    vicsoftware
                                    wrote on last edited by
                                    #23

                                    @fcarney I tried multipart. But we need several headers and file contents only. Without parsing parts and boundaries on server side cause server save all data to file.

                                    1 Reply Last reply
                                    0
                                    • V vicsoftware

                                      @fcarney Tried that:

                                      request.setHeader( QNetworkRequest::ContentLengthHeader, QVariant{ m_requestFile->size() } );
                                      request.setHeader( QNetworkRequest::ContentTypeHeader, QVariant{ "image/jpeg" } );
                                      

                                      Same bug.

                                      May be QT developers can help?

                                      fcarneyF Offline
                                      fcarneyF Offline
                                      fcarney
                                      wrote on last edited by
                                      #24

                                      @vicsoftware said in Post upload file send only 16kb:

                                      request.setHeader( QNetworkRequest::ContentTypeHeader, QVariant{ m_requestFile->size() } );
                                      request.setHeader( QNetworkRequest::ContentLengthHeader, QVariant{ "image/jpeg" } );

                                      Are you really setting length to "image/jpeg"? And type to size?

                                      C++ is a perfectly valid school of magic.

                                      V 1 Reply Last reply
                                      0
                                      • fcarneyF fcarney

                                        @vicsoftware said in Post upload file send only 16kb:

                                        request.setHeader( QNetworkRequest::ContentTypeHeader, QVariant{ m_requestFile->size() } );
                                        request.setHeader( QNetworkRequest::ContentLengthHeader, QVariant{ "image/jpeg" } );

                                        Are you really setting length to "image/jpeg"? And type to size?

                                        V Offline
                                        V Offline
                                        vicsoftware
                                        wrote on last edited by
                                        #25

                                        @fcarney Sorry, I'm tired. Fixed. Tried both ). Same result.

                                        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