Results 1 to 4 of 4

Thread: QNetworkRequest file upload -- please help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Thanked 2 Times in 1 Post

    Default Re: QNetworkRequest file upload -- please help

    UPDATE:

    Using WireShark I have been able to decipher that the $_FILES variable is just not being populated by the functioning of my QT application. I have read that this could potentially derive from an insufficiently high max_upload_size in php.ini, but with even the smallest file I see the same response.

    Using WireShark I also "cleaned up" the data sent to the php script. I'm still confused, though, about the necessity of certain headers. The arrangement I have now appears to work from within my program, but WireShark responds with my coded php response to !$_FILES (echo "no file" and a further "Bad Request ... Your browser sent a request that this server could not understand." in a continuation.

    Qt Code:
    1. // file init
    2. //inputFile.setFileName("test.csv");
    3. inputFile.setFileName("main.cpp");
    4. if(!inputFile.open(QFile::ReadOnly|QIODevice::Text)) {
    5. ui->textEdit->append("File failed to open - contact system administrator.");
    6.  
    7. } else {
    8. QString boundary,data,crlf,fileByteSize;
    9. QByteArray dataToSend;
    10.  
    11. boundary="-----------------------------7d935033608e2";
    12. crlf=0x0d;
    13. crlf+=0x0a;
    14.  
    15. data=crlf+"--"+boundary+crlf; // start delimiter
    16. data+="Content-Disposition: form-data; name=\"MAX_FILE_SIZE\";"+crlf+crlf;
    17. data+=fileByteSize.setNum(inputFile.size()+1);
    18. data+=crlf+"--"+boundary+crlf;
    19. data+="Content-Disposition: form-data; name=\"username\";"+crlf+crlf+"username"+crlf; // !! effect username !!
    20. data+=crlf+"--"+boundary+crlf;
    21. data+="Content-Disposition: form-data; name=\"password\";"+crlf+crlf+"password"+crlf; // !! effect password !!
    22. data+=crlf+"--"+boundary+crlf;
    23. data+="Content-Disposition: form-data; name=\"uploadedFile\"; filename=\"ContactList.csv\";"+crlf;
    24. data+="Content-Type: text/plain"+crlf+crlf+inputFile.readAll()+crlf;
    25. data+="--"+boundary+"--"+crlf; // stop delimiter
    26. dataToSend.insert(0,data); // convert to byte array for request
    27.  
    28. ui->textEdit->insertPlainText(dataToSend.data()); // update ui for my own sake
    29.  
    30. // request init
    31. QNetworkRequest request(QUrl("http://edm.localhost/uploader.php"));
    32. //request.setRawHeader("Content Type","text/plain");
    33.  
    34. //QString contentType="multipart/form-data; boundary=\""+boundary+"\"";
    35. //QString host="http://edm.localhost/";
    36.  
    37. //request.setRawHeader("Host",host.toAscii());
    38. // if (userAgentS!="") request.setRawHeader("User-Agent", userAgentS.toAscii());
    39. // if (refererS!="") request.setRawHeader("Referer", refererS.toAscii());
    40. //request.setHeader(QNetworkRequest::ContentTypeHeader,contentType.toAscii());
    41. //request.setHeader(QNetworkRequest::ContentLengthHeader,QVariant(inputFile.size()).toString());
    42. //request.setUrl(QUrl("http://edm.localhost"));
    43.  
    44. //request.setRawHeader("Content Disposition","form-data; name=\"uploadedFile\"; filename=\"DownloadedContactList.csv\"");
    45. //request.setRawHeader("Content Length",dataToSend);//fileByteSize.setNum(inputFile.size()));
    46. //request.setHeader(QNetworkRequest::ContentTypeHeader,"multipart/form-data; boundary: -----------------------------7d935033608e2\n");
    47. request.setHeader(QNetworkRequest::ContentLengthHeader,inputFile.size());
    48.  
    49. reply=manager.post(request,dataToSend); // perform post request
    50.  
    51. // QByteArray data = reply->readAll();
    52. // QTextStream out(&data);
    53. // QString file = out.readAll();
    54.  
    55. ui->textEdit->append(reply->readAll());
    56.  
    57. // connections
    58. connect(reply,SIGNAL(uploadProgress(qint64,qint64)),SLOT(mySetValue(qint64,qint64)));
    59. connect(reply,SIGNAL(finished()),SLOT(replyFinished())); // reply finished - close file
    To copy to clipboard, switch view to plain text mode 


    Any insight would be greatly appreciated.
    Last edited by wysota; 13th July 2009 at 22:47. Reason: missing [code] tags

Similar Threads

  1. How to upload file to HTTP server (POST Method)
    By Alex Snet in forum Qt Programming
    Replies: 8
    Last Post: 24th January 2011, 22:49
  2. Replies: 5
    Last Post: 20th January 2009, 14:11
  3. File Binary Upload QHttp find the bug/s
    By patrik08 in forum Qt Programming
    Replies: 13
    Last Post: 10th June 2008, 07:51
  4. QHttp::post() - cannot upload file
    By arunredi in forum Qt Programming
    Replies: 5
    Last Post: 16th May 2008, 12:13
  5. how to use qftp to upload file in just one procedure?
    By cxl2253 in forum Qt Programming
    Replies: 4
    Last Post: 23rd April 2007, 09:57

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.