Results 1 to 14 of 14

Thread: File Binary Upload QHttp find the bug/s

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default File Binary Upload QHttp find the bug/s

    I take part of this code on Qt Programming ... forum ..... and not running...

    I have 2 choise webdav ( http://www.webdav.org/neon/ & make libs ) upload or
    QHttp qt 4.1.3 upload ...

    class here running and signal is incomming....
    but 0 KB upload.... Why?

    full code is on svn http://ciz.ch/svnciz/_STATIC_LIBS_QT4/upload_test/


    Qt Code:
    1. #include "gui_upload.h"
    2. //
    3. /* Save file as gui_upload.cpp */
    4. /* Class Gui_Upload Created on Wed Jun 7 10:17:12 CEST 2006 */
    5. //
    6. #include <QCloseEvent>
    7. //
    8. QPointer<Gui_Upload> Gui_Upload::_self = 0L;
    9. //
    10. Gui_Upload* Gui_Upload::self( QWidget* parent )
    11. {
    12. if ( !_self )
    13. _self = new Gui_Upload( parent );
    14. return _self;
    15. }
    16. Gui_Upload::Gui_Upload( QWidget* parent )
    17. : QDialog( parent )
    18. {
    19. setupUi( this );
    20. qDebug() << "### class init ";
    21. connect(pushButton , SIGNAL(clicked()), this , SLOT(BeginnJob()));
    22. }
    23.  
    24. void Gui_Upload::FinishStream()
    25. {
    26. QMessageBox::information(this, tr("HTTP"),tr("Signal finisch!"));
    27. }
    28. void Gui_Upload::BeginnJob()
    29. {
    30. QString us = username->text();
    31. QString pa = pass->text();
    32. QString openFilesPath = "/";
    33.  
    34. if (us.size() < 1 or pa.size() < 1) {
    35. QMessageBox::information(this, tr("HTTP"),tr("User Name or Pass not set!"));
    36. return;
    37. }
    38. qDebug() << "### user " << us;
    39. qDebug() << "### pass " << pa;
    40. qDebug() << "### openFilesPath " << openFilesPath;
    41.  
    42. QString fileName = QFileDialog::getOpenFileName(this,tr("OpenFile"),openFilesPath,tr("All Files (*);;Text Files (*.txt)"));
    43. if (!fileName.isEmpty()) {
    44. openFilesPath = fileName;
    45. qDebug() << "### openFilesPath " << openFilesPath;
    46. QFileInfo path(openFilesPath);
    47. QString fileName1 = path.fileName();
    48. userfile = new QFile(openFilesPath);
    49. if ( !userfile->open(QIODevice::ReadOnly) ) {
    50. QMessageBox::information(this, tr("HTTP"),tr("Unable to open the file %1: %2.").arg(openFilesPath).arg(userfile->errorString()));
    51. return;
    52. }
    53. pushButton->setEnabled(false);
    54.  
    55. /* dear qt set and splitt the url self */
    56. QUrl url("http://ppk.go/qt/tools.php");
    57. QHttpRequestHeader header("POST", url.path());
    58. header.setValue("Host", url.host());
    59. header.setValue("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; it-IT; rv:1.7.12) Gecko/20050919 Firefox/1.0.7");
    60. header.setValue("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
    61. header.setValue("Accept-Language", "de-de,it;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2");
    62. header.setValue("Accept-Encoding", "gzip,deflate");
    63. header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    64. header.setValue("Keep-Alive", "300");
    65. header.setValue("Connection", "keep-alive");
    66. header.setValue("Referer", "http://ppk.go/");
    67. header.setValue("Content-Type", "application/x-www-form-urlencoded");
    68.  
    69. QByteArray byt(openFilesPath.toUtf8());
    70. QByteArray bytes;
    71. bytes.append("--AaB03x\r\n");
    72. bytes.append("content-disposition: ");
    73. bytes.append("form-data; name=\"onlyclient\" username=\""+us+"\" password=\""+pa+"\" action=\"beamup\" \r\n");
    74. bytes.append("\r\n");
    75. bytes.append("0\r\n");
    76. bytes.append("--AaB03x\r\n");
    77. bytes.append("content-disposition: ");
    78. bytes.append("form-data; name=\"qtfile\"; filename=\"" + byt+ "\"\r\n");
    79. bytes.append("Content-Transfer-Encoding: binary\r\n");
    80. bytes.append("\r\n");
    81. bytes.append(userfile->readAll());
    82. userfile->close();
    83. bytes.append("\r\n");
    84. bytes.append("--AaB03x--");
    85.  
    86. int contentLength = bytes.length();
    87. header.setContentLength(contentLength);
    88.  
    89. qDebug() << "### stream " << bytes;
    90.  
    91. /* real post */
    92. http = new QHttp(this);
    93. int httpGetId = http->request(header, bytes);
    94. qDebug() << "### httpGetId " << httpGetId;
    95. /* real post */
    96. connect(http, SIGNAL(done(bool)), this, SLOT(FinishStream()));
    97. }
    98.  
    99. }
    100.  
    101. void Gui_Upload::closeEvent( QCloseEvent* e )
    102. {
    103. e->accept();
    104. }
    To copy to clipboard, switch view to plain text mode 

    the form is so ... and firefox upload sucessfull....

    Qt Code:
    1. <form action="tools.php" method="post" enctype="multipart/form-data" name="onlyclient" id="onlyclient">
    2. <input type="hidden" name="action" value="beamup">
    3. Username:<br/><input type="text" name="username"><br/><br/>
    4. Password:<br/><input type="password" name="password"><br/><br/>
    5.  
    6. Your File:<BR><input type=file name=qtfile><BR><BR>
    7. <input type=submit name=submit value="Upload">
    8. </form>
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: File Binary Upload QHttp find the bug/s

    I tested other method ....

    server has method POST but variable become $_SERVER["vars"] and not $_POST[vars]

    Why?

    Qt Code:
    1. pushButton->setEnabled(false);
    2. /* dear qt set and splitt the url self */
    3. QUrl url(weburlpostget);
    4. /* HEADER ONLY _SERVER["HTTP_PASSWORD"] */
    5. QHttpRequestHeader header("POST",url.path(), 1, 1);
    6. header.setValue("Host",url.host());
    7. header.setContentType("multipart/form-data");
    8. header.setValue("username", "afaf346afa");
    9. header.setValue("password", "sg233646fg");
    10. header.setValue("pirlo", "dsgdsdgf315125dsgsdg/");
    11. header.setValue("afafaff", "dsgdsd35215asfagdsgsdg/");
    12. header.setValue("afafafa", "dsgdsa525325sfadgdsgsdg/");
    13.  
    14. QByteArray *bytes = new QByteArray();
    15. bytes->append("-----------------------------125282808721657\n");
    16. bytes->append("Content-Disposition: form-data; name=\"\"; ");
    17. bytes->append("filename=\"kommnimmmich.txt\"\n");
    18. bytes->append("Content-length: 1");
    19. bytes->append("\nContent-Type: text/plain\n\n");
    20. bytes->append("hoi.");
    21. http_0 = new QHttp(this);
    22. http_0->setHost(url.host());
    23. http_0->post(url.path(),bytes);
    24. httpGetId = http_0->request(header,bytes,0);
    25. connect(http_0, SIGNAL(done(bool)), this, SLOT(FinishStream()));
    To copy to clipboard, switch view to plain text mode 


    on php file i put a log to grab action....

    Qt Code:
    1. /* begin file #ob_start(); */
    2. $puffermg=ob_get_contents();
    3. while (@ob_end_clean());
    4. file_put_contents("lastaction.html",$puffermg);
    5. print($puffermg);
    6. exit;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: File Binary Upload QHttp find the bug/s

    But what do you want to do? Upload a file to a remote server using POST?

    IMO you need to do the following:

    Qt Code:
    1. QHttp *http = new QHttp(this);
    2. http->setHost("somehost");
    3. QFile *file = new QFile("somefile", http); // substitute with other QIODevice if you need
    4. file->open(QIODevice::ReadOnly);
    5. connect(http, SIGNAL(done(bool)), http, SLOT(deleteLater()));
    6. http->post("/path/to/send/post/request", file);
    To copy to clipboard, switch view to plain text mode 

    Of course you can substitute QHttp::post() with QHttp::request() if you fill all the needed headers properly.

    And be prepared to change the encoding of the data if need be.
    Last edited by wysota; 7th June 2006 at 18:35.

  4. #4
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: File Binary Upload QHttp find the bug/s

    I like to become $_POST[vars] on server..... and upload file on same time ... only xml text file and image....

    $_POST['unixtime'] $_FILE['ssss.xml']

    and server put file on dir
    $path = function(unixtime)
    news/2006/06/1149699402/ssss.xml

    firefox make $_POST[vars] .... php work fine.... but qt make $_SERVER[vars]

    i not find the correct method ... ->request or ->post

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: File Binary Upload QHttp find the bug/s

    If you want to send it as a file, IMO you should use QHttp::request, because you need a custom header to tell the script on the other side, that the data sent is a file. But the general idea of my code still stands.

    I think you should use some network sniffer (ethereal or netcat would be best here) and see what headers should be set for correct file upload.

  6. #6
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: File Binary Upload QHttp find the bug/s

    I search on my old php4 script a similar function..... to give arguments on post...

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($Ffields));
    same as...
    curl_setopt($ch, CURLOPT_POSTFIELDS,"login=foo&password=bar");

    all vars from CURLOPT_POSTFIELDS become $_POST...

    How to find correct header info to send? is possibel that qt cann handle that... or ist faster to bring on curl?



    Qt Code:
    1. $Ffields=array(
    2. "__EVENTTARGET" => "repLang:_ct0:lbLang",
    3. "__EVENTARGUMENT" => 'repLang$_ct0$lbLang',
    4. "__VIEWSTATE" => $this->VIEWSTATE, /* asp secure nummer session read ... and transfer to all page. on read.. */
    5. "dlg1:ctrl1:tbKunde" => "252525",
    6. "dlg1:ctrl1:tbKuerzel" => "2352352",
    7. "dlg1:ctrl1:PasswordTexBox" => "ygygsgsg",
    8. "dlg1:ctrl1:cbPersistentLogin" => "on",
    9. "dlg1:ctrl1:Btn_Login" => "Anmelden");
    10.  
    11. $ch = curl_init();
    12. curl_setopt ($ch, CURLOPT_URL, $url);
    13. curl_setopt ($ch, CURLOPT_POST,true);
    14. curl_setopt ($ch, CURLOPT_USERAGENT, $this->Set_Agent());
    15. curl_setopt($ch, CURLOPT_COOKIEJAR, $this->Workdir.'/also_cookie.txt');
    16. curl_setopt($ch, CURLOPT_COOKIEFILE, $this->Workdir.'/also_cookie.txt');
    17. curl_setopt ($ch, CURLOPT_HEADER, 0);
    18. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($Ffields));
    19. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    20. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    21. curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    22. curl_setopt ($ch, CURLOPT_TIMEOUT, 12);
    23. $resultxml = curl_exec ($ch)
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: File Binary Upload QHttp find the bug/s

    Do as I already said -- take a network sniffer, activate it, open your browser, load the form that sends the file, submit the form and check in the sniffer, what headers were sent to the server. Then mimic them using QHttp. And remember that you actually have to POST those key=value pairs. Setting them as headers won't do. You have to properly set the content-length and send the data as content and not as headers. If you use a network sniffer, you'll know exactly how should the data be sent.

  8. #8
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: File Binary Upload QHttp find the bug/s

    I have install http://livehttpheaders.mozdev.org/
    and firefox make so.....

    Only header go to server but not _POST vars arguments.....



    POST /qt/tools.php HTTP/1.1
    Host: ppk.go
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it-IT; rv:1.7.12) Gecko/20050919 Firefox/1.0.7
    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Language: de-de,it;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    Referer: http://ppk.go/qt/tools.php
    Content-Type: multipart/form-data; boundary=---------------------------41184676334
    Content-Length: 5604
    -----------------------------41184676334
    Content-Disposition: form-data; name="action"

    beamup
    -----------------------------41184676334
    Content-Disposition: form-data; name="username"

    sfgs
    -----------------------------41184676334
    Content-Disposition: form-data; name="password"

    g<sgsg
    -----------------------------41184676334
    Content-Disposition: form-data; name="qtfile"; filename="gui_upload.ui"
    Content-Type: application/octet-stream



    And I put un code so two method ...


    Qt Code:
    1. void Gui_Upload::BeginnJob()
    2. {
    3. bool method_1 = true;
    4. QString openFilesPath = "/";
    5. QDateTime timer2( QDateTime::currentDateTime() );
    6. const uint MAXWAITING = timer2.addSecs(8).toTime_t();
    7. const QString POSTID = QString( "11478%1\r\n" ).arg( QString::number(MAXWAITING) );
    8. const QString POSTIDEND = QString( "11478%1--\r\n" ).arg( QString::number(MAXWAITING) );
    9. qDebug() << "### POSTID " << POSTID;
    10. QString us = username->text();
    11. QString pa = pass->text();
    12. QString posturl = "http://ppk.go/qt/tools.php?id=test";
    13.  
    14. if (us.size() < 1 or pa.size() < 1) {
    15. QMessageBox::information(this, tr("HTTP"),tr("User Name or Pass not set!"));
    16. return;
    17. }
    18. qDebug() << "### user " << us;
    19. qDebug() << "### pass " << pa;
    20.  
    21. pushButton->setEnabled(false);
    22.  
    23. QString fileName = QFileDialog::getOpenFileName(this,tr("OpenFile"),openFilesPath,tr("All Files (*);;Text Files (*.txt)"));
    24. if (!fileName.isEmpty()) {
    25. qDebug() << "### fileName " << fileName;
    26. }
    27.  
    28.  
    29. /* dear qt set and splitt the url self */
    30. QUrl url(posturl);
    31. qDebug() << "### host " << url.host();
    32. qDebug() << "### path " << url.path();
    33. QHttpRequestHeader header("POST",url.path());
    34. header.setValue("Host",url.host());
    35. header.setValue("User-Agent", "QT4 4.1.3 QHttp troll method 1");
    36. header.setValue("Accept", "text/plain");
    37. header.setValue("Accept-Language", "en-us");
    38. header.setValue("Accept-Encoding", "gzip,deflate");
    39. header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    40. header.setValue("Keep-Alive", "300");
    41. header.setValue("Connection", "keep-alive");
    42. header.setValue("Referer", "http://ppk.go/qt/tools.php");
    43. header.setValue("Content-Type", "multipart/form-data; boundary=---------------------------"+POSTID);
    44.  
    45. QByteArray bytes;
    46. bytes.append("-----------------------------"+POSTID);
    47. bytes.append("Content-Disposition: form-data; name=\"action\"\r\n");
    48. bytes.append("beamup\r\n");
    49. bytes.append("-----------------------------"+POSTID);
    50. bytes.append("Content-Disposition: form-data; name=\"submit\"\r\n");
    51. bytes.append("Upload\r\n");
    52. bytes.append("-----------------------------"+POSTID);
    53. bytes.append("Content-Disposition: form-data; name=\"username\"\r\n");
    54. bytes.append(us+"\r\n");
    55. bytes.append("-----------------------------"+POSTID);
    56. bytes.append("Content-Disposition: form-data; name=\"password\"\r\n");
    57. bytes.append(pa+"\r\n");
    58. bytes.append("-----------------------------"+POSTID);
    59. bytes.append("Content-Disposition: form-data; name=\"unixtime\"\r\n");
    60. bytes.append(QString::number(MAXWAITING)+"\r\n");
    61.  
    62. if (method_1) {
    63. qDebug() << "### METHOD 1 start ++++++++++++++++++++ ";
    64. QString dateiName;
    65. file = new QFile();
    66. QFileInfo fileInfo(fileName);
    67. file->setFileName(fileName);
    68. dateiName = fileInfo.fileName();
    69.  
    70. bytes.append("-----------------------------"+POSTID);
    71. bytes.append("Content-Disposition: form-data; name=\"qtfile\"; filename=\""+dateiName+"\"\n");
    72. bytes.append("Content-length: " + QString::number(fileInfo.size()));
    73. bytes.append("\nContent-Type: text/plain\n\n");
    74. bytes.append(file->readAll());
    75.  
    76.  
    77. header.setValue("Content-Length", QString::number(fileInfo.size()));
    78.  
    79.  
    80. http_0 = new QHttp(url.host(),80,this);
    81. httpGetId = http_0->request(header, bytes);
    82. qDebug() << "### post httpGetId " << httpGetId;
    83. connect(http_0, SIGNAL(done(bool)), this, SLOT(FinishStream()));
    84. connect(http_0, SIGNAL(dataSendProgress(int,int)), this, SLOT(WriteNowProgress(int,int)));
    85. file->close();
    86. qDebug() << "### METHOD 1 end ++++++++++++++++++++ ";
    87.  
    88. } else {
    89.  
    90. qDebug() << "### METHOD 2 start ++++++++++++++++++++ ";
    91. QUrl www(posturl);
    92. qDebug() << "### host " << www.host();
    93. qDebug() << "### path " << www.path();
    94. QHttp *http = new QHttp(this);
    95. http->setHost(www.host());
    96. QFile *file = new QFile(fileName, http);
    97. file->open(QIODevice::ReadOnly);
    98. connect(http, SIGNAL(done(bool)), this, SLOT(FinishStream()));
    99. http->post(www.path(), file);
    100. qDebug() << "### METHOD 2 end ++++++++++++++++++++ ";
    101. }
    102.  
    103. qDebug() << "### POSTID " << POSTID;
    104. qDebug() << "### POSTID " << POSTID;
    105. qDebug() << "### POSTID " << POSTID;
    106. qDebug() << "### POSTID " << POSTID;
    107. qDebug() << "### POSTID " << POSTID;
    108.  
    109. }
    To copy to clipboard, switch view to plain text mode 

    Result are so .... method 1 or 2 are same .... only header diff
    I work on php5 , debian sarge , and fastcgi apache2 suexec all file is user ppk and apache runn as user ppk.....
    and firefox can upload file and set variabel _POST...

    I suppose qt write class to http on other server ..... or php4



    _SERVER["HTTP_HOST"] ppk.go
    _SERVER["HTTP_USER_AGENT"] QT4 4.1.3 QHttp troll method 1
    _SERVER["HTTP_ACCEPT"] text/plain
    _SERVER["HTTP_ACCEPT_LANGUAGE"] en-us
    _SERVER["HTTP_ACCEPT_ENCODING"] gzip,deflate
    _SERVER["HTTP_ACCEPT_CHARSET"] ISO-8859-1,utf-8;q=0.7,*;q=0.7
    _SERVER["HTTP_KEEP_ALIVE"] 300
    _SERVER["HTTP_CONNECTION"] keep-alive
    _SERVER["HTTP_REFERER"] http://ppk.go/qt/tools.php
    _SERVER["CONTENT_TYPE"] multipart/form-data; boundary=---------------------------114781149811467
    _SERVER["PATH"] /usr/local/bin:/usr/bin:/bin
    _SERVER["SERVER_SIGNATURE"] <address>Apache/2.0.54 (Debian GNU/Linux) DAV/2 PHP/5.0.4-0.9sarge1 mod_perl/1.999.21 Perl/v5.8.4 Server at ppk.go Port 80</address>
    _SERVER["SERVER_SOFTWARE"] Apache/2.0.54 (Debian GNU/Linux) DAV/2 PHP/5.0.4-0.9sarge1 mod_perl/1.999.21 Perl/v5.8.4
    _SERVER["SERVER_NAME"] ppk.go
    _SERVER["SERVER_ADDR"] 192.168.1.32
    _SERVER["SERVER_PORT"] 80
    _SERVER["REMOTE_ADDR"] 192.168.1.34
    _SERVER["DOCUMENT_ROOT"] /home/ppk/www/ppk.go/
    _SERVER["SERVER_ADMIN"] [no address given]
    _SERVER["SCRIPT_FILENAME"] /home/ppk/www/ppk.go/qt/tools.php
    _SERVER["REMOTE_PORT"] 4423
    _SERVER["GATEWAY_INTERFACE"] CGI/1.1
    _SERVER["SERVER_PROTOCOL"] HTTP/1.1
    _SERVER["REQUEST_METHOD"] POST
    _SERVER["QUERY_STRING"] no value
    _SERVER["REQUEST_URI"] /qt/tools.php
    _SERVER["SCRIPT_NAME"] /qt/tools.php
    _SERVER["PHP_SELF"] /qt/tools.php
    _SERVER["argv"]

    Array
    (
    )

    _SERVER["argc"] 0
    _ENV["PATH"] /usr/local/bin:/usr/bin:/bin
    _ENV["PWD"] /
    _ENV["LANG"] C
    _ENV["SHLVL"] 1
    _ENV["_"] /usr/sbin/apache2

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: File Binary Upload QHttp find the bug/s

    Apart from the first one, I didn't understand a single sentence you wrote.

    Does it work now or not?

  10. #10
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: File Binary Upload QHttp find the bug/s

    Not work only header.setValue("Content-Type", "multipart/form-data boundary=---------------------------125282808721657");
    go to server, & no variable and no file ...... go up to server i tink muss work on apache2 and php5 / 6

    I test now http://www.qtforum.de/forum/viewtopic.php?t=2255 is incomming tody on Snippets, Tipps & Tricks

  11. #11
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: File Binary Upload QHttp find the bug/s

    Impossibel to upload file or set variable apache2 & php5.... i discovery a faster method ...
    The key is Webdav http://www.webdav.org/ only window muss install external mount disk tool .... webdrive or netdrive ....

    advantage ... i can check evry time if mounted by hidden file
    if file exist mount otherwise ..... not....

    And send to disk evry file and variable ...

    Qt Code:
    1. void Setting_Gui::WebdavSetup()
    2. {
    3. label_webdav->setText(tr("Your OS Not Support Webdav"));
    4. QStringList diskremote;
    5. QString disksetting = Global_Config(APPLICATION_SETTING,"webdav_root");
    6. #if defined Q_WS_WIN
    7. /* http://ciz.ch/service/98,1142862047/de/ netdrive webdrive */
    8. label_webdav->setText(tr("Window XP/2000 OS: Webdav Root (Radice)"));
    9. QString alfa ="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
    10. diskremote = alfa.split(",");
    11. webdav_root->clear();
    12. int loop= 0 - 1;
    13. int activeselected;
    14. QStringListIterator o(diskremote);
    15. while (o.hasNext()) {
    16. loop++;
    17. QString disker = o.next().toLocal8Bit().constData();
    18. QString diskeree = disker.append(":/");
    19. webdav_root->addItem(diskeree);
    20. if (disksetting == diskeree) {
    21. activeselected = loop;
    22. }
    23. }
    24. webdav_root->setEditable(false);
    25. webdav_root->setCurrentIndex(activeselected);
    26. #endif
    27. #if defined Q_WS_MAC
    28. /* apple + K */
    29. label_webdav->setText(tr("Mac OS: Mount Disk Webdav Root"));
    30. QString listdiron ="/Volumes/";
    31. webdav_root->addItem(disksetting);
    32. /* webdav_root->addItem(listdiron);*/
    33. QDir dir(listdiron);
    34. if (dir.exists()) {
    35. const QFileInfoList list = dir.entryInfoList();
    36. for (int i = 0; i < list.size(); i++)
    37. {
    38. fi = list.at(i);
    39. if (fi.isDir() && fi.fileName() != "." && fi.fileName() != "..") {
    40. QString disker = fi.absoluteFilePath();
    41. QString diskeree = disker.append("/");
    42. webdav_root->addItem(diskeree);
    43. }
    44. }
    45. }
    46. webdav_root->setEditable(false);
    47. #endif
    48.  
    49. #if defined Q_WS_X11
    50. /* http://www.webdav.org/cadaver/ */
    51. label_webdav->setText(tr("Linux OS: Mount Disk Webdav Root"));
    52. QString listdiron ="/mnt/";
    53. webdav_root->setEditable(true);
    54. webdav_root->addItem(disksetting);
    55. webdav_root->addItem(listdiron);
    56. #endif
    57.  
    58. }
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: File Binary Upload QHttp find the bug/s

    Quote Originally Posted by patrik08
    QString disker = o.next().toLocal8Bit().constData();
    Can't you just write
    Qt Code:
    1. QString disker = o.next();
    To copy to clipboard, switch view to plain text mode 
    ?

    If o.next() contains characters that local encoding can't handle, you will loose information.

  13. The following user says thank you to jacek for this useful post:

    patrik08 (9th June 2006)

  14. #13
    Join Date
    Apr 2008
    Location
    California
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: File Binary Upload QHttp find the bug/s

    Hello,

    did you figure what was the problem with Qhttp binary upload?

    I'm doing something similar but my problem is that the app posts only partial file to the server. I am able to upload files like xml/ txt in complete even though they are 200 KB or more. But when I try to upload files like jpg/ png they are uploaded partlially. most of the times the file posted to the server is less than 40 kb although the actuall size is around 1 MB or more.

    here is part of my code:
    Qt Code:
    1. http = new QHttp(this);
    2. connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
    3. this, SLOT(readResponseHeaderFilePosted(const QHttpResponseHeader &)));
    4. http->setHost(hostName);
    5. if (proxyEnable)
    6. http->setProxy(proxyName, proxyPort);
    7. QByteArray data;
    8. QString boundary="-----------------------------AaB03x";
    9. QString endline="\r\n";
    10. QString start_delim="--"+boundary+endline;
    11. QString cont_disp_str="Content-Disposition: form-data; ";
    12. QString user_str = start_delim + cont_disp_str + "name=" + "\"user\""+endline+endline+userName+endline;
    13. data.append(QString(user_str).toUtf8());
    14. QString pass_str = start_delim + cont_disp_str + "name=" + "\"pass\""+endline+endline+passCode+endline;
    15. data.append(QString(pass_str).toUtf8());
    16. QString proj_str = start_delim + cont_disp_str + "name=" + "\"project_name\""+endline+endline+projName+endline;
    17. data.append(QString(proj_str).toUtf8());
    18. QString projId_str = start_delim + cont_disp_str + "name=" + "\"project_id\""+endline+endline+projId+endline;
    19. data.append(QString(projId_str).toUtf8());
    20. QString title_str = start_delim + cont_disp_str + "name=" + "\"title\""+endline+endline+only_filename+endline;
    21. data.append(QString(title_str).toUtf8());
    22. userfile = new QFile(filePath);
    23. if (userfile->open(QIODevice::ReadOnly)){
    24. QString file_str = start_delim + cont_disp_str + "name=" + "\"uploadfile1\""+ ";filename="+ "\""+ filePath +"\""+endline + "Content-Type: image/jpeg" +endline+endline+ userfile->readAll()+ endline;
    25. //bytes.append("Content-Transfer-Encoding: binary\r\n"); Content-Type: image/jpeg application/octet-stream
    26. file_str = file_str +endline;
    27. data.append(QString(file_str));
    28. userfile->close(); // the file is opened earlier in the code
    29. //QMessageBox::critical(this, "Arun_file_str", file_str, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
    30. }
    31.  
    32. QString v_str = start_delim + cont_disp_str + "name=" + "\"v\""+endline+endline+"1.0"+endline;
    33. data.append(QString(v_str).toUtf8());
    34. QString cmd_str = start_delim + cont_disp_str + "name=" + "\"command\""+endline+endline+"add"+endline;
    35. data.append(QString(cmd_str).toUtf8());
    36. QString stop_delim="--"+boundary+"--"+endline;
    37. data.append(QString(stop_delim).toUtf8());
    38. QHttpRequestHeader header("POST", postHeader);
    39. header.setValue("Host", hostName);
    40. header.setValue("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14");
    41. header.setValue("Accept", "image/jpeg,image/jpg,text/xml,application/xml,application/xhtml+xml,text/html;q=0.7,text/plain;q=0.8,image/png,*/*;q=0.9");
    42. header.setValue("Accept-Language", "en-us,en;q=0.5");
    43. header.setValue("Accept-Encoding" ,"gzip,deflate");
    44. header.setValue("Accept-Charset" ,"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    45. header.setValue("Cookie" ,"country=US; lang=en");
    46. header.setContentType("multipart/form-data, boundary=-----------------------------AaB03x");
    47. header.setContentLength(data.length());
    48. http->request(header, data);
    To copy to clipboard, switch view to plain text mode 

    I suspect that the string is getting truncted when I'm trying to read the QByteArray into QString on the below line:
    QString file_str = start_delim + cont_disp_str + "name=" + "\"uploadfile1\""+ ";filename="+ "\""+ filePath +"\""+endline + "Content-Type: image/jpeg" +endline+endline+ userfile->readAll()
    any insights???

    Thanks,
    Last edited by arunredi; 10th June 2008 at 05:33.
    - AR

  15. #14
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: File Binary Upload QHttp find the bug/s

    I solved my problem on PUT Method Upload...

    If you believe or not the old HTTP PUT method is 60% faster as the conventional method!



    You send Only file upload ++ autenficate chunk on cookie.... PUT header

    http://www.qtforum.de/forum/viewtopic.php?t=3085

    on php site i use PoPoon http://wiki.flux-cms.org/display/FLX/Popoon

    if you dont have access on server..... mist...

    Qt Code:
    1. <?php
    2. /* davimage.php */
    3.  
    4. include_once("popoon/components/action.php");
    5. /**
    6. * http://bx.ppk.go/page/movie/page/movie/upimzip/bio/13462346/
    7. * http://bx.ppk.go/page/movie/page/movie/upimzip/film/13462346/
    8. */
    9.  
    10.  
    11.  
    12.  
    13.  
    14.  
    15.  
    16.  
    17.  
    18. class popoon_components_actions_davcmszip extends popoon_components_action {
    19.  
    20. /**
    21.   * Constructor
    22.   *
    23.   */
    24.  
    25.  
    26.  
    27.  
    28.  
    29. function Reset_Dir($dir) {
    30. $dirfos = $dir;
    31. if (is_dir($dirfos)) {
    32. $d = dir($dirfos);
    33. $mone=0;
    34. while (false !== ($entry = $d->read())) {
    35. if ($entry == "." or $entry =="..") {
    36. continue;
    37. }
    38. if (is_dir($dirfos.$entry)) { /// is_dir bug???
    39. continue;
    40. }
    41. if (is_file($dirfos.$entry)) {
    42. @unlink($dirfos.$entry);
    43. $mone++;
    44. }
    45. }
    46.  
    47. }
    48. }
    49.  
    50.  
    51. function Make_Dir($dir) {
    52. if (eregi('data', $dir)) {
    53. @shell_exec(escapeshellcmd('mkdir -p '.$dir)); ///PHP FastCGI from owner or www-data ///
    54. if (!is_dir($dir)) {
    55. print("<h1>ERROR Permission Denied! (Make_Dir ".$dir.")</h1> <p>".__FILE__."#".__LINE__."<p>");
    56. exit;
    57. } else {
    58. return true;
    59. }
    60. } else {
    61. print("<h1>ERROR Permission Denied! (Make_Dir ".$dir.")</h1> <p>".__FILE__."#".__LINE__."<p>");
    62. return false;
    63. }
    64.  
    65. return false;
    66. }
    67.  
    68. function ResetCache() {
    69. $dirfos = CACHEWEBS;
    70. if (is_dir($dirfos)) {
    71. $d = dir($dirfos);
    72. $mone=0;
    73. while (false !== ($entry = $d->read())) {
    74. if ($entry == "." or $entry =="..") {
    75. continue;
    76. }
    77. if (is_dir($dirfos.$entry)) { /// is_dir bug???
    78. continue;
    79. }
    80.  
    81. if (is_file($dirfos.$entry)) {
    82.  
    83. @unlink($dirfos.$entry);
    84.  
    85. $mone++;
    86. }
    87. }
    88. return $mone;
    89. } else {
    90. return 0;
    91. }
    92.  
    93. }
    94.  
    95. /* get zip stream and replace on dbs */
    96. function TakeZipDB( $path , $uintid ) {
    97.  
    98. if (!@$fd = fopen($path, "rb")) {
    99. return false;
    100. }
    101.  
    102. $dbaccess = new DB_Service(DBASE_0);
    103.  
    104. $magic_quotes = get_magic_quotes_runtime();
    105. set_magic_quotes_runtime(0);
    106. $file_buffer = fread($fd, filesize($path));
    107. $file_buffer = base64_encode($file_buffer);
    108. $file_buffer .="|end_stream|"; /* help to find if longblob having more as 2.4 mb sql query size en come in or no.. */
    109. fclose($fd);
    110. set_magic_quotes_runtime($magic_quotes);
    111. $sqlreplacezip = "REPLACE INTO PAGEFILE VALUES (".$uintid.", 'zip', 'attach' ,'".$file_buffer."',".date("U").")";
    112. $kbgo = file_put_contents(CACHEWEBS."lastzibdb.dat",$sqlreplacezip);
    113.  
    114. return $dbaccess->Exec_SQL($sqlreplacezip);
    115.  
    116. if ($kbgo > 0) {
    117. return true;
    118. } else {
    119. return false;
    120. }
    121. }
    122.  
    123.  
    124.  
    125. function action_davcmszip(&$sitemap) {
    126. $this->action($sitemap);
    127. }
    128.  
    129. function init() {
    130.  
    131. }
    132.  
    133. function act() {
    134. $canno = ""; /* message action */
    135. $openzipondir = "/root/"; /* on place wo not is permission to write! default ! */
    136. $filewriter = ROOT_WWW_DIR."map/datazip.xml"; /* file mit retour info */
    137. $code = $this->getParameterDefault("code"); /* file mit retour info */
    138. $methodbrowser = strtolower($_SERVER['REQUEST_METHOD']);
    139. $kb=0;
    140. $errors="";
    141. $canno="";
    142. $teile = @explode("/", $code);
    143. $filenr = $teile[0];
    144. $methode = $teile[1];
    145. $usefile = $teile[2];
    146.  
    147.  
    148. $oneday_yahr = date('Y',$filenr);
    149. $oneday_month = date('m',$filenr);
    150. $oneday_tag = date('d',$filenr);
    151. $userbasedir = "data/".$oneday_yahr."/".$oneday_month."/".$oneday_tag."/";
    152. $basedir = ROOT_WWW_DIR."data/".$oneday_yahr."/".$oneday_month."/".$oneday_tag."/";
    153. $basepagedir = $basedir.$filenr."/";
    154. $imageedir = $basedir.$filenr."/album/";
    155. $datadir = $basedir.$filenr."/data/";
    156. $subjektfile = $basedir.$filenr.".zip";
    157.  
    158.  
    159. if ($methodbrowser == "get" && $methode !="remove") {
    160. $canno .="Test envoirment|";
    161. $canno .="Usage filenr/data/zip/ to create page.|";
    162. $canno .="Usage cache/remove/file/ to drop cache file.|";
    163. }
    164.  
    165. if ($methodbrowser == "put" && $methode =="data") {
    166. $canno .="Accept upload.|";
    167. }
    168.  
    169. if (!isset($_COOKIE['Xserial'])) {
    170. $errors .="You dont have a serial permission denied!|";
    171. } else {
    172.  
    173. if (is_numeric($filenr) && $methode =="data") {
    174. if ($_COOKIE['Xserial'] == QTSERIAL) {
    175. $canno .="Your serial is correct.|";
    176.  
    177. if ($this->Make_Dir($basedir)) {
    178. $canno .="Dir exist page|";
    179. if ($methodbrowser == "put") {
    180. $canno .="Reading input.|";
    181. ///////@unlink($subjektfile);
    182. $content = file_get_contents("php://input");
    183. $kb=file_put_contents($subjektfile,$content);
    184. /* replace zip on db here */
    185. $this->Reset_Dir($imageedir);
    186. $this->Reset_Dir($datadir);
    187. $this->Reset_Dir($basepagedir);
    188. $zipreq = @exec(escapeshellcmd('unzip '.$subjektfile.' -d '.$basedir));
    189. $this->ResetCache();
    190. if ($this->TakeZipDB($subjektfile,$filenr)) {
    191. $canno .="Zip ON DB OK|";
    192. }
    193. @unlink($subjektfile);
    194. $canno .="Unzip MSG start.|";
    195. $canno .=$zipreq.".|";
    196. $canno .="Unzip MSG stop.|";
    197. }
    198.  
    199. }
    200. }
    201. }
    202.  
    203. }
    204.  
    205.  
    206.  
    207.  
    208.  
    209.  
    210.  
    211. $dml = new XML('1.0', 'utf-8');
    212. $root = $dml->createElement('dav_zip_upload');
    213. $root->setAttribute('methode',$methode);
    214. $root->setAttribute('httpm',$methodbrowser);
    215. $root->setAttribute('filenr',$filenr);
    216. $root->setAttribute('usefile',$userbasedir);
    217.  
    218. if (isset($_COOKIE['Xserial'])) {
    219.  
    220. if ($_COOKIE['Xserial'] == QTSERIAL) {
    221. $root->setAttribute('youserial',"1");
    222. } else {
    223. $root->setAttribute('youserial',"NULL");
    224. }
    225. }
    226.  
    227. $root->setAttribute('buildindate',date("U"));
    228. $root->setAttribute('hbuild',date("d.m.Y-G:i:s"));
    229.  
    230.  
    231.  
    232.  
    233. $root->setAttribute('kb_in',$kb);
    234. $dml->appendChild($root);
    235. $nome = $dml->createElement("message",$canno);
    236. $root->appendChild($nome);
    237.  
    238. $erno = $dml->createElement("erno",$errors);
    239. $root->appendChild($erno);
    240.  
    241. $dxbio = $dml->saveXML();
    242. @file_put_contents($filewriter,$dxbio);
    243. return array("message" => "how take message");
    244. }
    245.  
    246. }
    247.  
    248. ?>
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 13
    Last Post: 1st June 2006, 15: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.