11-27-2012 03:56 PM - edited 11-27-2012 04:00 PM
found a bug in QHttpMultiPart causing problems to upload files
here's the bug: https://bugreports.qt-project.org/browse/QTBUG-254
the bug is fixed: https://codereview.qt-project.org/#change,24142
but not in the Qt Version bundled with Cascades
QHttpMultiPart is missing a CRLF at the end after the last boundary.
Any idea to workaround ?
appended some Parts to the Multipart and then do a Post
mNetworkAccessManager->post(request, mRequestMultipart);
have no idea HowTo add a CRLF to the Multipart and want to avoid to construct the complex MultiPart manually
ekke
see also this thread: http://supportforums.blackberry.com/t5/Cascades-De
Solved! Go to Solution.
11-28-2012 01:49 AM
Qt 4.8.3 fixed the bug 25429 http://qt.digia.com/Release-Notes/Release-Notes-Qt
hopefully Cascades will be bundled with Qt 4.8.3 soon
12-03-2012 06:41 PM
I finally had success in uploading an image along with some other parameters.
QString fn = QDir::currentPath() + "/app/native/assets/images/icon.png";
QNetworkAccessManager* netManager = new QNetworkAccessManager();
if (!netManager)
{
qDebug() << "Unable to create QNetworkAccessManager!";
emit complete("Unable to create QNetworkAccessManager!", false);
return;
}
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart commentPart;
commentPart.setHeader(QNetworkRequest::ContentDisp ositionHeader, QVariant("form-data; name=\"comment\""));
commentPart.setBody("Comment goes here");
QHttpPart namePart;
namePart.setHeader(QNetworkRequest::ContentDisposi tionHeader, QVariant("form-data; name=\"name\""));
namePart.setBody("Name goes here");
QHttpPart imagePart;
imagePart.setHeader(QNetworkRequest::ContentTypeHe ader, "image/png");
imagePart.setHeader(QNetworkRequest::ContentDispos itionHeader, QVariant("form-data; name=\"image\"; filename=\"icon.png\""));
QFile *file = new QFile(fn);
file->open(QIODevice::ReadOnly);
imagePart.setBodyDevice(file);
file->setParent(multiPart);
multiPart->append(commentPart);
multiPart->append(namePart);
multiPart->append(blankImagePart);
multiPart->append(sectionPart);
multiPart->append(latPart);
multiPart->append(lonPart);
multiPart->append(imagePart);
QString queryUri = "http://your.urlhere.com";
QUrl url(queryUri);
QNetworkRequest req(url);
QNetworkReply* ipReply = netManager->post(req, multiPart);
connect(ipReply, SIGNAL(finished()), this, SLOT(commentDataReceived()));
12-03-2012 06:46 PM
thx
I will do more tests tomorrow evening with a manual implementation and also with Beta 4 where Qt 4.8.4 is integrated where the bug should be fixed as I got infos from RIM
...will let you know (and also take a look at your code)
12-05-2012 09:18 AM
thx rnickel - comparing with your code I found the reason:
there was one line too much in my code:
request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data");
I had to comment this out and now it works. (The bug with QHttpMultiPart and missing CRLF at the end is fixed with Qt 4.8.4 bundled with Cascades)
Seems that QHttpMultiPart was too intelligent and comfortable for me ;-)
...but should be mentioned in the docs that the multipart-header must not be set or should be ignored