PDA

View Full Version : Problem in Http file upload



dipeshtech
26th April 2011, 23:38
I am trying to upload a .csv file on my server. Referring the documentation, i have written the following code. But, there is some problem and it's not working.

I am calling doUpload() for the upload action:




uploadmanager::uploadmanager()
{
connect(&manager, SIGNAL(finished(QNetworkReply*)),
SLOT(uploadFinished(QNetworkReply*)));
}


void uploadmanager::doUpload()
{
QStringList args;
QString message_d = QString("Unable to open file");
args<<"E:\\SMSAssassin\\spam_freq.csv";

foreach (QString arg, args) {

QFile file(arg);
if (!file.open(QIODevice::ReadOnly))
{
QMessageBox::information(this, "Error", message_d);
return;
}

QNetworkRequest request;
request.setUrl(QUrl("http://ddd.myserver.com/smssp/uploads/"));
request.setHeader(QNetworkRequest::ContentTypeHead er,"application/x-www-form-urlencoded");
file.open(QIODevice::ReadOnly);
QByteArray fileBinaryData(file.readAll());
file.close();
QNetworkReply *reply = manager.put(request, fileBinaryData);

currentUploads.append(reply);
}

}

void uploadmanager::uploadFinished(QNetworkReply *reply)
{
//QUrl url = reply->url();
if (reply->error())
{
QString message_er = QString("Error in Upload");
QMessageBox::information(this, "Err", message_er);
}
else
{
QString message_d = QString("Upload Complete");
QMessageBox::information(this, "Upload Complete", message_d);

}

currentUploads.removeAll(reply);
reply->deleteLater();

if (currentUploads.isEmpty())
return;

}




Any help will be appreciated.

high_flyer
28th April 2011, 09:44
But, there is some problem and it's not working.
The first step is to debug the code.
Step through doUbload() and look which code is not behaving as it should.
Your code makes almost no tests for many of the calls you make, so any of those could be failing.
Once you know which line of code is the problem, we can look more in to it.