Results 1 to 2 of 2

Thread: Problem in Http file upload

  1. #1
    Join Date
    Mar 2011
    Location
    New Delhi, India
    Posts
    31
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Problem in Http file upload

    I am trying to upload a .csv file on my server. Referring the documentation, i have written the following code. But, there is some problem and it's not working.

    I am calling doUpload() for the upload action:

    Qt Code:
    1. uploadmanager::uploadmanager()
    2. {
    3. connect(&manager, SIGNAL(finished(QNetworkReply*)),
    4. SLOT(uploadFinished(QNetworkReply*)));
    5. }
    6.  
    7.  
    8. void uploadmanager::doUpload()
    9. {
    10. QString message_d = QString("Unable to open file");
    11. args<<"E:\\SMSAssassin\\spam_freq.csv";
    12.  
    13. foreach (QString arg, args) {
    14.  
    15. QFile file(arg);
    16. if (!file.open(QIODevice::ReadOnly))
    17. {
    18. QMessageBox::information(this, "Error", message_d);
    19. return;
    20. }
    21.  
    22. QNetworkRequest request;
    23. request.setUrl(QUrl("http://ddd.myserver.com/smssp/uploads/"));
    24. request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
    25. file.open(QIODevice::ReadOnly);
    26. QByteArray fileBinaryData(file.readAll());
    27. file.close();
    28. QNetworkReply *reply = manager.put(request, fileBinaryData);
    29.  
    30. currentUploads.append(reply);
    31. }
    32.  
    33. }
    34.  
    35. void uploadmanager::uploadFinished(QNetworkReply *reply)
    36. {
    37. //QUrl url = reply->url();
    38. if (reply->error())
    39. {
    40. QString message_er = QString("Error in Upload");
    41. QMessageBox::information(this, "Err", message_er);
    42. }
    43. else
    44. {
    45. QString message_d = QString("Upload Complete");
    46. QMessageBox::information(this, "Upload Complete", message_d);
    47.  
    48. }
    49.  
    50. currentUploads.removeAll(reply);
    51. reply->deleteLater();
    52.  
    53. if (currentUploads.isEmpty())
    54. return;
    55.  
    56. }
    To copy to clipboard, switch view to plain text mode 

    Any help will be appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem in Http file upload

    But, there is some problem and it's not working.
    The first step is to debug the code.
    Step through doUbload() and look which code is not behaving as it should.
    Your code makes almost no tests for many of the calls you make, so any of those could be failing.
    Once you know which line of code is the problem, we can look more in to it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Upload file to HTTP server
    By produktdotestow in forum Qt Programming
    Replies: 5
    Last Post: 30th July 2011, 14:18
  2. Replies: 0
    Last Post: 28th February 2011, 09:10
  3. errors while upload files on http server????
    By sups in forum Qt Programming
    Replies: 4
    Last Post: 25th February 2011, 23:11
  4. 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
  5. QHttp "PUT METHOD" QT Problem File Upload. RFC 2616
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 25th October 2006, 22:02

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.