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. QNAM slow upload compared to browser
Forum Updated to NodeBB v4.3 + New Features

QNAM slow upload compared to browser

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 438 Views
  • 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.
  • W Offline
    W Offline
    Wallboy
    wrote on last edited by Wallboy
    #1

    Hey everyone,

    I'm having an issue with a multipart/form-data upload being much slower than when I make the exact same upload in my browser to my web server. If I use a test form on my Firefox browser, I can max out my upload connection of 20Mbit. However when using QNAM, I am only getting 6.5 Mbit/s with the exact same upload. Here is my test program in PyQt 5.7:

    from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply, QHttpMultiPart, QHttpPart
    from PyQt5.QtCore import QUrl, QFile, QByteArray, QIODevice
    from PyQt5.QtWidgets import QApplication, QMainWindow
    import sys
    import ui_test
    
    
    class Upload(QMainWindow, ui_test.Ui_MainWindow):
        def __init__(self):
            super().__init__()
            self.setupUi(self)
    
            self.pushButton.clicked.connect(self.doUpload)
    
            self.manager = QNetworkAccessManager()
            self.url = QUrl('http://MyWebServer.com/post.php')
    
        def doUpload(self):
            multiPart = QHttpMultiPart(QHttpMultiPart.FormDataType)
    
            filePart = QHttpPart()
            filePart.setHeader(QNetworkRequest.ContentDispositionHeader, 'form-data; name="upload_file"; filename="testfile.mp4"')
            filePart.setHeader(QNetworkRequest.ContentTypeHeader, 'video/mp4')
            videoFile = QFile('testfile.mp4')
            videoFile.open(QIODevice.ReadOnly)
    	# fileInBytes = videoFile.readAll()
            filePart.setBodyDevice(videoFile)  # Maximum ~6.5 Megabit/s
    	# filePart.setBody(fileInBytes) # Maximum ~6.5 Megabit/s
            videoFile.setParent(multiPart) 
    
            multiPart.append(filePart)
    
            request = QNetworkRequest(self.url)
    
            request.setRawHeader(b'User-Agent', b'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0')
            request.setRawHeader(b'Accept', b'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
            request.setRawHeader(b'Accept-Language', b'en-US,en;q=0.5')
            request.setRawHeader(b'Accept-Encoding', b'gzip, deflate')
            request.setRawHeader(b'Connection', b'keep-alive')
            request.setRawHeader(b'Upgrade-Insecure-Requests', b'1')
    
            self.reply = self.manager.post(request, multiPart)
    	# self.reply = self.manager.post(request, fileInBytes) # Maximum ~6.5 Megabit/s
            multiPart.setParent(self.reply)
            self.reply.finished.connect(self.finishedUpload)
            self.reply.uploadProgress.connect(self.slotUploadProgress)
    
        def finishedUpload(self):
            self.reply.deleteLater()
            self.reply = None
    
        def slotUploadProgress(self, bytesSent, bytesTotal):
            sent = str(bytesSent)
            total = str(bytesTotal)
            print(sent + ' bytes of ' + total)
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        main_window = Upload()
        main_window.show()
        sys.exit(app.exec_())
    
    

    I have tried 3 different ways of uploading the data:

    1. using setBodyDevice() to stream the file upload. Result is 6.5 Mbit/s
    2. using setBody() and read the entire file first into memory. Result is again 6.5 Mbit/s
    3. Skipping QHttp*/multipart all-together and using manager.post(request, fileInBytes). Result is again 6.5 Mbit/s

    I have also matched the request headers that my browser would normally send to rule out anything there. At this point I am out of ideas on why it's so much slower than when uploading through my browser.

    EDIT: I have tried some other test POST servers and I'm getting faster speeds, so I think the issue is likely on my server. But I would still like to know what is going on that would cause the POST to be fast on my browser, but not in my QNAM application?

    Any help would be appreciated. Thanks.

    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