Results 1 to 7 of 7

Thread: [QT5.3:Windows7]File upload through QNetworkAccessManager, memory spiking with proxy

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default [QT5.3:Windows7]File upload through QNetworkAccessManager, memory spiking with proxy

    I am using qt(5.3) on windows 7(vs2008)(below code, skipping the details) to upload a file which is on the disk. if the proxy is not enabled on the system,
    upload is working fine for any size(i tried ~3gb) without spiking memory for my application(~22MB). But as i enable system proxy, memory for the application
    is growing propotional to uploadProgress. It works fine with file size below 1.3GB upload. As my application is 32 bit, it crashes(bad_alloc, in qt) if i try to
    upload more than 1.3GB file with proxy.

    So i have following queries:
    1) Are we loading complete file into memory if proxy is enabled?

    2) As i guess, we are not loading complete file into memory if proxy is not enabled. Can we do same thing if proxy is enabled? If yes, how can we achieve that?




    Qt Code:
    1. QNetworkReply* upload(const QString &title, const QString &path, const QString &payload, QNetworkRequest request, QNetworkAccessManager* nam)
    2.  
    3.  
    4.  
    5. QHttpMultiPart *pMultipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
    6. QHttpPart richPart;
    7. richPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"entity_document\""));
    8. richPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json; charset=UTF-8"));
    9. richPart.setBody(payload.toUtf8());
    10.  
    11. QString binaryHeader = "form-data; name=\"fileData\"; filename=\"";
    12. binaryHeader += title;
    13. binaryHeader += "\"";
    14.  
    15. QHttpPart binaryHeader;
    16. binaryHeader.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain; charset=UTF-8"));
    17. binaryHeader.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(binaryHeader));
    18.  
    19. QFile *fileP = new QFile(path);
    20. if(!fileP->open(QIODevice::ReadOnly))
    21. {
    22. //logging the error
    23. }
    24. binaryHeader.setBodyDevice(fileP);
    25. fileP->setParent(pMultipart);
    26.  
    27. pMultipart->append(richPart);
    28. pMultipart->append(binaryHeader);
    29.  
    30. m_replyP = nam->post(request, pMultipart);
    31. pMultipart->setParent(m_replyP);
    32. //bindall(); here binding finished() and uploadProgress signal
    33. return m_replyP;
    34. }
    35.  
    36. //Skipped normal memory cleanup
    To copy to clipboard, switch view to plain text mode 


    Applicatin initialization if Proxy is enabled on machine:
    Qt Code:
    1. QNetworkProxy applicationProxy = QNetworkProxy::applicationProxy();
    2.  
    3. applicationProxy.setUser(user);
    4. applicationProxy.setPassword(password);
    5.  
    6. QNetworkProxy::setApplicationProxy(applicationProxy);
    7. nam->setProxy(applicationProxy);
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 24th June 2015 at 15:39. Reason: missing [code] tags

Similar Threads

  1. FTP Upload using QNetworkAccessManager
    By replax in forum Newbie
    Replies: 2
    Last Post: 30th October 2014, 12:32
  2. Replies: 6
    Last Post: 4th June 2011, 00:07
  3. Replies: 1
    Last Post: 21st October 2010, 04:59
  4. Replies: 5
    Last Post: 20th January 2009, 14:11
  5. upload files using QNetworkAccessManager
    By Raajesh in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2008, 19:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.