Results 1 to 7 of 7

Thread: upload an executable file using QNetworkAccessManager

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    Greece
    Posts
    23
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default upload an executable file using QNetworkAccessManager

    I want to upload an executable file to the server.My code is this:
    Qt Code:
    1. QString data;
    2. QByteArray dataToSend; // byte array to be sent in POST
    3. QFile *inputFile=new QFile("putty.exe");
    4.  
    5. if(!inputFile->open(QIODevice::ReadOnly))
    6. return;
    7.  
    8. data+="\nContent-Disposition: form-data; ";
    9.  
    10. data+=QString("name=\"%1\"; ").arg(name);//putty
    11. data+=QString("filename=\"%1\";").arg(filepath);//http://localhost/uploadFiles/sdda/putty.exe
    12. data+="Content-Type: application/octet-stream" +inputFile->readAll();
    13.  
    14. dataToSend=data.toUtf8(); // convert data string to byte array for request
    15.  
    16. // request init
    17. QNetworkRequest request(QUrl("http://localhost/uploadFile.php"));
    18. request.setRawHeader("Content-Type"," multipart/form-data; boundary=\"-----------------------------7d935033608e2\"");
    19. request.setHeader(QNetworkRequest::ContentLengthHeader,dataToSend.size());
    To copy to clipboard, switch view to plain text mode 

    Running this code the result is:a warning that informs me that a folder in which i want to upload the file already exists.Is the above approach correct?

    //php script

    Qt Code:
    1. <
    2. ?php
    3.  
    4.  
    5. $packageName = trim($_POST['packageName']);
    6. mkdir("uploadFiles/$packageName");
    7. // Upload file
    8. move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'], "uploads/$packageName/{$_FILES['uploadFile'] ['name']}")
    9.  
    10. ?>
    To copy to clipboard, switch view to plain text mode 

    Thanks!
    Last edited by milli; 31st May 2011 at 00:36.

Similar Threads

  1. FTP Upload using QNetworkAccessManager
    By replax in forum Newbie
    Replies: 2
    Last Post: 30th October 2014, 12:32
  2. Replies: 1
    Last Post: 21st October 2010, 04:59
  3. Replies: 5
    Last Post: 15th June 2010, 07:42
  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.