PDA

View Full Version : File Binary Upload QHttp find the bug/s



patrik08
7th June 2006, 12:36
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/




#include "gui_upload.h"
//
/* Save file as gui_upload.cpp */
/* Class Gui_Upload Created on Wed Jun 7 10:17:12 CEST 2006 */
//
#include <QCloseEvent>
//
QPointer<Gui_Upload> Gui_Upload::_self = 0L;
//
Gui_Upload* Gui_Upload::self( QWidget* parent )
{
if ( !_self )
_self = new Gui_Upload( parent );
return _self;
}
Gui_Upload::Gui_Upload( QWidget* parent )
: QDialog( parent )
{
setupUi( this );
qDebug() << "### class init ";
connect(pushButton , SIGNAL(clicked()), this , SLOT(BeginnJob()));
}

void Gui_Upload::FinishStream()
{
QMessageBox::information(this, tr("HTTP"),tr("Signal finisch!"));
}
void Gui_Upload::BeginnJob()
{
QString us = username->text();
QString pa = pass->text();
QString openFilesPath = "/";

if (us.size() < 1 or pa.size() < 1) {
QMessageBox::information(this, tr("HTTP"),tr("User Name or Pass not set!"));
return;
}
qDebug() << "### user " << us;
qDebug() << "### pass " << pa;
qDebug() << "### openFilesPath " << openFilesPath;

QString fileName = QFileDialog::getOpenFileName(this,tr("OpenFile"),openFilesPath,tr("All Files (*);;Text Files (*.txt)"));
if (!fileName.isEmpty()) {
openFilesPath = fileName;
qDebug() << "### openFilesPath " << openFilesPath;
QFileInfo path(openFilesPath);
QString fileName1 = path.fileName();
userfile = new QFile(openFilesPath);
if ( !userfile->open(QIODevice::ReadOnly) ) {
QMessageBox::information(this, tr("HTTP"),tr("Unable to open the file %1: %2.").arg(openFilesPath).arg(userfile->errorString()));
return;
}
pushButton->setEnabled(false);

/* dear qt set and splitt the url self */
QUrl url("http://ppk.go/qt/tools.php");
QHttpRequestHeader header("POST", url.path());
header.setValue("Host", url.host());
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");
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");
header.setValue("Accept-Language", "de-de,it;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2");
header.setValue("Accept-Encoding", "gzip,deflate");
header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
header.setValue("Keep-Alive", "300");
header.setValue("Connection", "keep-alive");
header.setValue("Referer", "http://ppk.go/");
header.setValue("Content-Type", "application/x-www-form-urlencoded");

QByteArray byt(openFilesPath.toUtf8());
QByteArray bytes;
bytes.append("--AaB03x\r\n");
bytes.append("content-disposition: ");
bytes.append("form-data; name=\"onlyclient\" username=\""+us+"\" password=\""+pa+"\" action=\"beamup\" \r\n");
bytes.append("\r\n");
bytes.append("0\r\n");
bytes.append("--AaB03x\r\n");
bytes.append("content-disposition: ");
bytes.append("form-data; name=\"qtfile\"; filename=\"" + byt+ "\"\r\n");
bytes.append("Content-Transfer-Encoding: binary\r\n");
bytes.append("\r\n");
bytes.append(userfile->readAll());
userfile->close();
bytes.append("\r\n");
bytes.append("--AaB03x--");

int contentLength = bytes.length();
header.setContentLength(contentLength);

qDebug() << "### stream " << bytes;

/* real post */
http = new QHttp(this);
int httpGetId = http->request(header, bytes);
qDebug() << "### httpGetId " << httpGetId;
/* real post */
connect(http, SIGNAL(done(bool)), this, SLOT(FinishStream()));
}

}

void Gui_Upload::closeEvent( QCloseEvent* e )
{
e->accept();
}



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


<form action="tools.php" method="post" enctype="multipart/form-data" name="onlyclient" id="onlyclient">
<input type="hidden" name="action" value="beamup">
Username:<br/><input type="text" name="username"><br/><br/>
Password:<br/><input type="password" name="password"><br/><br/>

Your File:<BR><input type=file name=qtfile><BR><BR>
<input type=submit name=submit value="Upload">
</form>

patrik08
7th June 2006, 17:39
I tested other method ....

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

Why?



pushButton->setEnabled(false);
/* dear qt set and splitt the url self */
QUrl url(weburlpostget);
/* HEADER ONLY _SERVER["HTTP_PASSWORD"] */
QHttpRequestHeader header("POST",url.path(), 1, 1);
header.setValue("Host",url.host());
header.setContentType("multipart/form-data");
header.setValue("username", "afaf346afa");
header.setValue("password", "sg233646fg");
header.setValue("pirlo", "dsgdsdgf315125dsgsdg/");
header.setValue("afafaff", "dsgdsd35215asfagdsgsdg/");
header.setValue("afafafa", "dsgdsa525325sfadgdsgsdg/");

QByteArray *bytes = new QByteArray();
bytes->append("-----------------------------125282808721657\n");
bytes->append("Content-Disposition: form-data; name=\"\"; ");
bytes->append("filename=\"kommnimmmich.txt\"\n");
bytes->append("Content-length: 1");
bytes->append("\nContent-Type: text/plain\n\n");
bytes->append("hoi.");
http_0 = new QHttp(this);
http_0->setHost(url.host());
http_0->post(url.path(),bytes);
httpGetId = http_0->request(header,bytes,0);
connect(http_0, SIGNAL(done(bool)), this, SLOT(FinishStream()));


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


/* begin file #ob_start(); */
$puffermg=ob_get_contents();
while (@ob_end_clean());
file_put_contents("lastaction.html",$puffermg);
print($puffermg);
exit;

wysota
7th June 2006, 18:31
But what do you want to do? Upload a file to a remote server using POST?

IMO you need to do the following:


QHttp *http = new QHttp(this);
http->setHost("somehost");
QFile *file = new QFile("somefile", http); // substitute with other QIODevice if you need
file->open(QIODevice::ReadOnly);
connect(http, SIGNAL(done(bool)), http, SLOT(deleteLater()));
http->post("/path/to/send/post/request", file);

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.

patrik08
7th June 2006, 19:03
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

wysota
7th June 2006, 19:14
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.

patrik08
7th June 2006, 19:24
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?




$Ffields=array(
"__EVENTTARGET" => "repLang:_ct0:lbLang",
"__EVENTARGUMENT" => 'repLang$_ct0$lbLang',
"__VIEWSTATE" => $this->VIEWSTATE, /* asp secure nummer session read ... and transfer to all page. on read.. */
"dlg1:ctrl1:tbKunde" => "252525",
"dlg1:ctrl1:tbKuerzel" => "2352352",
"dlg1:ctrl1:PasswordTexBox" => "ygygsgsg",
"dlg1:ctrl1:cbPersistentLogin" => "on",
"dlg1:ctrl1:Btn_Login" => "Anmelden");

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST,true);
curl_setopt ($ch, CURLOPT_USERAGENT, $this->Set_Agent());
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->Workdir.'/also_cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->Workdir.'/also_cookie.txt');
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($Ffields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 12);
$resultxml = curl_exec ($ch)

wysota
7th June 2006, 19:45
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.

patrik08
9th June 2006, 02:16
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 ...





void Gui_Upload::BeginnJob()
{
bool method_1 = true;
QString openFilesPath = "/";
QDateTime timer2( QDateTime::currentDateTime() );
const uint MAXWAITING = timer2.addSecs(8).toTime_t();
const QString POSTID = QString( "11478%1\r\n" ).arg( QString::number(MAXWAITING) );
const QString POSTIDEND = QString( "11478%1--\r\n" ).arg( QString::number(MAXWAITING) );
qDebug() << "### POSTID " << POSTID;
QString us = username->text();
QString pa = pass->text();
QString posturl = "http://ppk.go/qt/tools.php?id=test";

if (us.size() < 1 or pa.size() < 1) {
QMessageBox::information(this, tr("HTTP"),tr("User Name or Pass not set!"));
return;
}
qDebug() << "### user " << us;
qDebug() << "### pass " << pa;

pushButton->setEnabled(false);

QString fileName = QFileDialog::getOpenFileName(this,tr("OpenFile"),openFilesPath,tr("All Files (*);;Text Files (*.txt)"));
if (!fileName.isEmpty()) {
qDebug() << "### fileName " << fileName;
}


/* dear qt set and splitt the url self */
QUrl url(posturl);
qDebug() << "### host " << url.host();
qDebug() << "### path " << url.path();
QHttpRequestHeader header("POST",url.path());
header.setValue("Host",url.host());
header.setValue("User-Agent", "QT4 4.1.3 QHttp troll method 1");
header.setValue("Accept", "text/plain");
header.setValue("Accept-Language", "en-us");
header.setValue("Accept-Encoding", "gzip,deflate");
header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
header.setValue("Keep-Alive", "300");
header.setValue("Connection", "keep-alive");
header.setValue("Referer", "http://ppk.go/qt/tools.php");
header.setValue("Content-Type", "multipart/form-data; boundary=---------------------------"+POSTID);

QByteArray bytes;
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"action\"\r\n");
bytes.append("beamup\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"submit\"\r\n");
bytes.append("Upload\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"username\"\r\n");
bytes.append(us+"\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"password\"\r\n");
bytes.append(pa+"\r\n");
bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"unixtime\"\r\n");
bytes.append(QString::number(MAXWAITING)+"\r\n");

if (method_1) {
qDebug() << "### METHOD 1 start ++++++++++++++++++++ ";
QString dateiName;
file = new QFile();
QFileInfo fileInfo(fileName);
file->setFileName(fileName);
dateiName = fileInfo.fileName();

bytes.append("-----------------------------"+POSTID);
bytes.append("Content-Disposition: form-data; name=\"qtfile\"; filename=\""+dateiName+"\"\n");
bytes.append("Content-length: " + QString::number(fileInfo.size()));
bytes.append("\nContent-Type: text/plain\n\n");
bytes.append(file->readAll());


header.setValue("Content-Length", QString::number(fileInfo.size()));


http_0 = new QHttp(url.host(),80,this);
httpGetId = http_0->request(header, bytes);
qDebug() << "### post httpGetId " << httpGetId;
connect(http_0, SIGNAL(done(bool)), this, SLOT(FinishStream()));
connect(http_0, SIGNAL(dataSendProgress(int,int)), this, SLOT(WriteNowProgress(int,int)));
file->close();
qDebug() << "### METHOD 1 end ++++++++++++++++++++ ";

} else {

qDebug() << "### METHOD 2 start ++++++++++++++++++++ ";
QUrl www(posturl);
qDebug() << "### host " << www.host();
qDebug() << "### path " << www.path();
QHttp *http = new QHttp(this);
http->setHost(www.host());
QFile *file = new QFile(fileName, http);
file->open(QIODevice::ReadOnly);
connect(http, SIGNAL(done(bool)), this, SLOT(FinishStream()));
http->post(www.path(), file);
qDebug() << "### METHOD 2 end ++++++++++++++++++++ ";
}

qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;
qDebug() << "### POSTID " << POSTID;

}



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

wysota
9th June 2006, 09:50
Apart from the first one, I didn't understand a single sentence you wrote.

Does it work now or not?

patrik08
9th June 2006, 14:50
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

patrik08
9th June 2006, 17:11
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 ...:)




void Setting_Gui::WebdavSetup()
{
label_webdav->setText(tr("Your OS Not Support Webdav"));
QStringList diskremote;
QString disksetting = Global_Config(APPLICATION_SETTING,"webdav_root");
#if defined Q_WS_WIN
/* http://ciz.ch/service/98,1142862047/de/ netdrive webdrive */
label_webdav->setText(tr("Window XP/2000 OS: Webdav Root (Radice)"));
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";
diskremote = alfa.split(",");
webdav_root->clear();
int loop= 0 - 1;
int activeselected;
QStringListIterator o(diskremote);
while (o.hasNext()) {
loop++;
QString disker = o.next().toLocal8Bit().constData();
QString diskeree = disker.append(":/");
webdav_root->addItem(diskeree);
if (disksetting == diskeree) {
activeselected = loop;
}
}
webdav_root->setEditable(false);
webdav_root->setCurrentIndex(activeselected);
#endif
#if defined Q_WS_MAC
/* apple + K */
label_webdav->setText(tr("Mac OS: Mount Disk Webdav Root"));
QString listdiron ="/Volumes/";
webdav_root->addItem(disksetting);
/* webdav_root->addItem(listdiron);*/
QDir dir(listdiron);
if (dir.exists()) {
const QFileInfoList list = dir.entryInfoList();
QFileInfo fi;
for (int i = 0; i < list.size(); i++)
{
fi = list.at(i);
if (fi.isDir() && fi.fileName() != "." && fi.fileName() != "..") {
QString disker = fi.absoluteFilePath();
QString diskeree = disker.append("/");
webdav_root->addItem(diskeree);
}
}
}
webdav_root->setEditable(false);
#endif

#if defined Q_WS_X11
/* http://www.webdav.org/cadaver/ */
label_webdav->setText(tr("Linux OS: Mount Disk Webdav Root"));
QString listdiron ="/mnt/";
webdav_root->setEditable(true);
webdav_root->addItem(disksetting);
webdav_root->addItem(listdiron);
#endif

}

jacek
9th June 2006, 17:15
QString disker = o.next().toLocal8Bit().constData();
Can't you just write
QString disker = o.next();?

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

arunredi
10th June 2008, 04:35
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:

http = new QHttp(this);
connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(readResponseHeaderFilePosted(const QHttpResponseHeader &)));
http->setHost(hostName);
if (proxyEnable)
http->setProxy(proxyName, proxyPort);
QByteArray data;
QString boundary="-----------------------------AaB03x";
QString endline="\r\n";
QString start_delim="--"+boundary+endline;
QString cont_disp_str="Content-Disposition: form-data; ";
QString user_str = start_delim + cont_disp_str + "name=" + "\"user\""+endline+endline+userName+endline;
data.append(QString(user_str).toUtf8());
QString pass_str = start_delim + cont_disp_str + "name=" + "\"pass\""+endline+endline+passCode+endline;
data.append(QString(pass_str).toUtf8());
QString proj_str = start_delim + cont_disp_str + "name=" + "\"project_name\""+endline+endline+projName+endline;
data.append(QString(proj_str).toUtf8());
QString projId_str = start_delim + cont_disp_str + "name=" + "\"project_id\""+endline+endline+projId+endline;
data.append(QString(projId_str).toUtf8());
QString title_str = start_delim + cont_disp_str + "name=" + "\"title\""+endline+endline+only_filename+endline;
data.append(QString(title_str).toUtf8());
userfile = new QFile(filePath);
if (userfile->open(QIODevice::ReadOnly)){
QString file_str = start_delim + cont_disp_str + "name=" + "\"uploadfile1\""+ ";filename="+ "\""+ filePath +"\""+endline + "Content-Type: image/jpeg" +endline+endline+ userfile->readAll()+ endline;
//bytes.append("Content-Transfer-Encoding: binary\r\n"); Content-Type: image/jpeg application/octet-stream
file_str = file_str +endline;
data.append(QString(file_str));
userfile->close(); // the file is opened earlier in the code
//QMessageBox::critical(this, "Arun_file_str", file_str, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
}

QString v_str = start_delim + cont_disp_str + "name=" + "\"v\""+endline+endline+"1.0"+endline;
data.append(QString(v_str).toUtf8());
QString cmd_str = start_delim + cont_disp_str + "name=" + "\"command\""+endline+endline+"add"+endline;
data.append(QString(cmd_str).toUtf8());
QString stop_delim="--"+boundary+"--"+endline;
data.append(QString(stop_delim).toUtf8());
QHttpRequestHeader header("POST", postHeader);
header.setValue("Host", hostName);
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");
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");
header.setValue("Accept-Language", "en-us,en;q=0.5");
header.setValue("Accept-Encoding" ,"gzip,deflate");
header.setValue("Accept-Charset" ,"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
header.setValue("Cookie" ,"country=US; lang=en");
header.setContentType("multipart/form-data, boundary=-----------------------------AaB03x");
header.setContentLength(data.length());
http->request(header, data);

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,

patrik08
10th June 2008, 08:51
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...



<?php
/* davimage.php */

include_once("popoon/components/action.php");
/**
* http://bx.ppk.go/page/movie/page/movie/upimzip/bio/13462346/
* http://bx.ppk.go/page/movie/page/movie/upimzip/film/13462346/
*/









class popoon_components_actions_davcmszip extends popoon_components_action {

/**
* Constructor
*
*/





function Reset_Dir($dir) {
$dirfos = $dir;
if (is_dir($dirfos)) {
$d = dir($dirfos);
$mone=0;
while (false !== ($entry = $d->read())) {
if ($entry == "." or $entry =="..") {
continue;
}
if (is_dir($dirfos.$entry)) { /// is_dir bug???
continue;
}
if (is_file($dirfos.$entry)) {
@unlink($dirfos.$entry);
$mone++;
}
}

}
}


function Make_Dir($dir) {
if (eregi('data', $dir)) {
@shell_exec(escapeshellcmd('mkdir -p '.$dir)); ///PHP FastCGI from owner or www-data ///
if (!is_dir($dir)) {
print("<h1>ERROR Permission Denied! (Make_Dir ".$dir.")</h1> <p>".__FILE__."#".__LINE__."<p>");
exit;
} else {
return true;
}
} else {
print("<h1>ERROR Permission Denied! (Make_Dir ".$dir.")</h1> <p>".__FILE__."#".__LINE__."<p>");
return false;
}

return false;
}

function ResetCache() {
$dirfos = CACHEWEBS;
if (is_dir($dirfos)) {
$d = dir($dirfos);
$mone=0;
while (false !== ($entry = $d->read())) {
if ($entry == "." or $entry =="..") {
continue;
}
if (is_dir($dirfos.$entry)) { /// is_dir bug???
continue;
}

if (is_file($dirfos.$entry)) {

@unlink($dirfos.$entry);

$mone++;
}
}
return $mone;
} else {
return 0;
}

}

/* get zip stream and replace on dbs */
function TakeZipDB( $path , $uintid ) {

if (!@$fd = fopen($path, "rb")) {
return false;
}

$dbaccess = new DB_Service(DBASE_0);

$magic_quotes = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
$file_buffer = fread($fd, filesize($path));
$file_buffer = base64_encode($file_buffer);
$file_buffer .="|end_stream|"; /* help to find if longblob having more as 2.4 mb sql query size en come in or no.. */
fclose($fd);
set_magic_quotes_runtime($magic_quotes);
$sqlreplacezip = "REPLACE INTO PAGEFILE VALUES (".$uintid.", 'zip', 'attach' ,'".$file_buffer."',".date("U").")";
$kbgo = file_put_contents(CACHEWEBS."lastzibdb.dat",$sqlreplacezip);

return $dbaccess->Exec_SQL($sqlreplacezip);

if ($kbgo > 0) {
return true;
} else {
return false;
}
}



function action_davcmszip(&$sitemap) {
$this->action($sitemap);
}

function init() {

}

function act() {
$canno = ""; /* message action */
$openzipondir = "/root/"; /* on place wo not is permission to write! default ! */
$filewriter = ROOT_WWW_DIR."map/datazip.xml"; /* file mit retour info */
$code = $this->getParameterDefault("code"); /* file mit retour info */
$methodbrowser = strtolower($_SERVER['REQUEST_METHOD']);
$kb=0;
$errors="";
$canno="";
$teile = @explode("/", $code);
$filenr = $teile[0];
$methode = $teile[1];
$usefile = $teile[2];


$oneday_yahr = date('Y',$filenr);
$oneday_month = date('m',$filenr);
$oneday_tag = date('d',$filenr);
$userbasedir = "data/".$oneday_yahr."/".$oneday_month."/".$oneday_tag."/";
$basedir = ROOT_WWW_DIR."data/".$oneday_yahr."/".$oneday_month."/".$oneday_tag."/";
$basepagedir = $basedir.$filenr."/";
$imageedir = $basedir.$filenr."/album/";
$datadir = $basedir.$filenr."/data/";
$subjektfile = $basedir.$filenr.".zip";


if ($methodbrowser == "get" && $methode !="remove") {
$canno .="Test envoirment|";
$canno .="Usage filenr/data/zip/ to create page.|";
$canno .="Usage cache/remove/file/ to drop cache file.|";
}

if ($methodbrowser == "put" && $methode =="data") {
$canno .="Accept upload.|";
}

if (!isset($_COOKIE['Xserial'])) {
$errors .="You dont have a serial permission denied!|";
} else {

if (is_numeric($filenr) && $methode =="data") {
if ($_COOKIE['Xserial'] == QTSERIAL) {
$canno .="Your serial is correct.|";

if ($this->Make_Dir($basedir)) {
$canno .="Dir exist page|";
if ($methodbrowser == "put") {
$canno .="Reading input.|";
///////@unlink($subjektfile);
$content = file_get_contents("php://input");
$kb=file_put_contents($subjektfile,$content);
/* replace zip on db here */
$this->Reset_Dir($imageedir);
$this->Reset_Dir($datadir);
$this->Reset_Dir($basepagedir);
$zipreq = @exec(escapeshellcmd('unzip '.$subjektfile.' -d '.$basedir));
$this->ResetCache();
if ($this->TakeZipDB($subjektfile,$filenr)) {
$canno .="Zip ON DB OK|";
}
@unlink($subjektfile);
$canno .="Unzip MSG start.|";
$canno .=$zipreq.".|";
$canno .="Unzip MSG stop.|";
}

}
}
}

}







$dml = new XML('1.0', 'utf-8');
$root = $dml->createElement('dav_zip_upload');
$root->setAttribute('methode',$methode);
$root->setAttribute('httpm',$methodbrowser);
$root->setAttribute('filenr',$filenr);
$root->setAttribute('usefile',$userbasedir);

if (isset($_COOKIE['Xserial'])) {

if ($_COOKIE['Xserial'] == QTSERIAL) {
$root->setAttribute('youserial',"1");
} else {
$root->setAttribute('youserial',"NULL");
}
}

$root->setAttribute('buildindate',date("U"));
$root->setAttribute('hbuild',date("d.m.Y-G:i:s"));




$root->setAttribute('kb_in',$kb);
$dml->appendChild($root);
$nome = $dml->createElement("message",$canno);
$root->appendChild($nome);

$erno = $dml->createElement("erno",$errors);
$root->appendChild($erno);

$dxbio = $dml->saveXML();
@file_put_contents($filewriter,$dxbio);
return array("message" => "how take message");
}

}

?>