Results 1 to 4 of 4

Thread: QNetworkRequest file upload -- please help

Threaded View

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

    Default QNetworkRequest file upload -- please help

    Hey folks - thank you so much for your help. Most of this is pretty new to me, and I have been able to only get so far. Could someone familiar with QNetworkRequest and php please help me see where I am going astray?

    Patching together several other attempts by various people I came up with this code to upload a file via POST to a php upload script. My code:

    ... from on_button_clicked() ...

    Qt Code:
    1. QString bound,data,crlf;
    2. QByteArray dataToSend;
    3.  
    4. bound="---------------------------7d935033608e2";
    5. crlf=0x0d;
    6. crlf+=0x0a;
    7. data="--"+bound+crlf+"Content-Disposition: form-data; name=\"uploadedFile\";";
    8. data+="filename=\"Contact List.csv\"";
    9. data+=crlf+"Content-Type: text/plain"+crlf+crlf;
    10. data+=inputFile.readAll(); // insert content of text file
    11. data+=crlf+"--"+bound+"--"+crlf;
    12. dataToSend.insert(0,data); // correct/needed?
    13.  
    14. // request init
    15. QNetworkRequest request(QUrl("http://edm.localhost/uploader.php"));
    16. // need to set headers here?
    17. reply=manager.post(request,dataToSend); // perform post request
    18.  
    19. // connections
    20. connect(reply,SIGNAL(uploadProgress(qint64,qint64)),
    21. SLOT(mySetValue(qint64,qint64)));
    22. connect(reply,SIGNAL(finished()),SLOT(replyFinished())); // reply finished - close file
    To copy to clipboard, switch view to plain text mode 



    and my php script is:
    html Code:
    1. <?php
    2. $target_path = "";
    3.  
    4. if($_FILES['uploadedFile']['name'])
    5. $target_path= $target_path.basename($_FILES['uploadedFile']['name']);
    6. else
    7. echo "no file name";
    8. echo "<br>";
    9.  
    10. if(move_uploaded_file($_FILES['uploadedFile']['tmp_name'], $target_path))
    11. echo "The file ".basename( $_FILES['uploadedFile']['name'])." has been uploaded";
    12. else
    13. echo "There was an error uploading the file, please try again!";
    14. ?>
    To copy to clipboard, switch view to plain text mode 

    The program seems to function, i.e. no errors or unexpected quitting and the progress bar updates through 100%, but I never receive the uploaded file in my upload directory (or elsewhere) as I do when I access this script through the following HTML form.

    html Code:
    1. <form enctype="multipart/form-data" action="uploader.php" method="POST">
    2. <input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
    3. Choose a file to upload: <input name="uploadedFile" type="file" /><br />
    4. <input type="submit" value="Upload File" />
    5. </form>
    To copy to clipboard, switch view to plain text mode 

    I'm running a QT4.5 (coding in QTCreator 4.5.2) on an UBUNTU 8.10 LAMP server. Thank you so much for any help!
    Last edited by wysota; 13th July 2009 at 09:20. 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.