Results 1 to 7 of 7

Thread: QHttpMultiPart - sending image to web serwer question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QHttpMultiPart - sending image to web serwer question

    You should use the _FILES super global to access binary uploaded files from a temporary directory on the server
    OR
    encode the binary data as Base64 (or some other text only encoding) for use in the _POST variable.

    See http://php.net/manual/en/features.file-upload.php

    To have the file appear in _FILES modify the doc example:
    Qt Code:
    1. QHttpPart imagePart;
    2. imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
    3. imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\"; filename=\"image.jpg\"")); // <<< filename triggers separate handling
    4. QFile *file = new QFile("image.jpg");
    5. file->open(QIODevice::ReadOnly);
    6. imagePart.setBodyDevice(file);
    7. file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart
    To copy to clipboard, switch view to plain text mode 
    and then you will see in the PHP environment:
    Qt Code:
    1. chrisw@newton /tmp/simple_example $ ./simple_example
    2. // _POST array
    3. array(1) {
    4. ["text"]=>
    5. string(7) "my text"
    6. }
    7. // _FILES array
    8. array(1) {
    9. ["image"]=>
    10. array(5) {
    11. ["name"]=>
    12. string(9) "image.jpg"
    13. ["type"]=>
    14. string(10) "image/jpeg"
    15. ["tmp_name"]=>
    16. string(14) "/tmp/phpaLYWWk"
    17. ["error"]=>
    18. int(0)
    19. ["size"]=>
    20. int(16246)
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QHttpMultiPart - sending image to web serwer question

    ok, thanks for help, i'am going to try it tomorrow at work and see how it works

Similar Threads

  1. sending soap request using QNetworkAccessManager question
    By babymonsta in forum Qt Programming
    Replies: 10
    Last Post: 21st April 2010, 08:55
  2. Replies: 1
    Last Post: 23rd October 2009, 19:23
  3. sending image one class to another class
    By rajini333 in forum Qt Programming
    Replies: 4
    Last Post: 4th June 2009, 10:45
  4. Sending a image using QSocket & QServerSocket
    By machathu in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2006, 13:23
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 20:01

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.