Reputation: 519
I'm trying to upload an image to an apache server using Qt's QNetworkAccessManager class using the POST method. What I don't get is, how to set appropriate QNetworkRequest::ContentTypeHeader and QNetworkRequest::ContentLengthHeader for an image? If the ContentTypeHeader is "multipart/form-data", what should the boundary be set as?
Sample Code:
data = new QFile("/home/darshan/aindra/1.png", this);
if (data->open(QIODevice::ReadOnly))
{
manager = new QNetworkAccessManager();
req.setUrl(QUrl(upload_url));
//space for req.setHeader() - contenttypeheader
//space for req.setHeader() - contentlengthheader
//reply = manager->post(req, QByteArray);
connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(requestFinished(QNetworkReply*)));
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(uploadProgress(qint64, qint64)));
}
else
{
qDebug() << "Could not open file to FTP";
}
Upvotes: 1
Views: 2003
Reputation: 29886
Since Qt 4.8, you can use QHttpMultipart
to upload files with QNetworkAccessManager
.
http://doc.qt.io/qt-4.8/qhttpmultipart.html
Upvotes: 2